From e1aa1c3cd8bb8556db62c81a94b4d0707b33c930 Mon Sep 17 00:00:00 2001 From: Sebastian Renner Date: Mon, 15 Jul 2019 09:34:15 +0200 Subject: [PATCH] Working towards F7 template --- templates/f7/Src/main.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------- templates/f7/f7.ioc | 45 +++++++++++++++++++++++---------------------- templates/f7/flash.jlink | 7 +++++++ templates/f7/middleware.py | 3 ++- 4 files changed, 85 insertions(+), 73 deletions(-) create mode 100644 templates/f7/flash.jlink diff --git a/templates/f7/Src/main.c b/templates/f7/Src/main.c index 7fa18f0..8db2e62 100644 --- a/templates/f7/Src/main.c +++ b/templates/f7/Src/main.c @@ -80,7 +80,7 @@ PCD_HandleTypeDef hpcd_USB_OTG_FS; void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USB_OTG_FS_PCD_Init(void); -static void MX_UART4_Init(void); +static void MX_USART2_Init(void); static void read_variable_serial(unsigned char action); static void write_variable_serial(unsigned char target[], uint32_t len); @@ -90,8 +90,8 @@ static void read_serial(void *dst, unsigned int len) { dbg_printf("Reading %d serial bytes\n", len); #endif for (int i = 0; i < len; i++) { - while (!LL_USART_IsActiveFlag_RXNE(UART4)); - buf[i] = LL_USART_ReceiveData8(UART4); + while (!LL_USART_IsActiveFlag_RXNE(USART2)); + buf[i] = LL_USART_ReceiveData8(USART2); } #ifdef DEBUG dbg_printf("done.\n", len); @@ -104,8 +104,8 @@ static void write_serial(const void *src, unsigned int len) { #ifdef DEBUG dbg_printf("Write to serial: %02x\n", buf[i]); #endif - while (!(LL_USART_IsActiveFlag_TXE(UART4))); - LL_USART_TransmitData8(UART4, buf[i]); + while (!(LL_USART_IsActiveFlag_TXE(USART2))); + LL_USART_TransmitData8(USART2, buf[i]); #ifdef DEBUG dbg_printf("Done writing!\n"); #endif @@ -194,7 +194,7 @@ int main(void) /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USB_OTG_FS_PCD_Init(); - MX_UART4_Init(); + MX_USART2_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ @@ -237,9 +237,9 @@ int main(void) dbg_printf("p: "); for (int i = 0; i < nplen; i++) dbg_printf("%02x", npub[i]); dbg_printf("\n"); dbg_printf("k: "); for (int i = 0; i < klen; i++) dbg_printf("%02x", k[i]); dbg_printf("\n"); #endif - LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_14); + //LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_14); res = crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k); - LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_14); + //LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_14); break; default: @@ -249,7 +249,6 @@ int main(void) /* USER CODE END WHILE */ } } - /** * @brief System Clock Configuration * @retval None @@ -295,53 +294,53 @@ void SystemClock_Config(void) LL_SYSTICK_SetClkSource(LL_SYSTICK_CLKSOURCE_HCLK); LL_SetSystemCoreClock(72000000); LL_RCC_SetUSBClockSource(LL_RCC_USB_CLKSOURCE_PLL); - LL_RCC_SetUARTClockSource(LL_RCC_UART4_CLKSOURCE_PCLK1); + LL_RCC_SetUSARTClockSource(LL_RCC_USART2_CLKSOURCE_PCLK1); } /** - * @brief UART4 Initialization Function + * @brief USART2 Initialization Function * @param None * @retval None */ -static void MX_UART4_Init(void) +static void MX_USART2_Init(void) { - /* USER CODE BEGIN UART4_Init 0 */ + /* USER CODE BEGIN USART2_Init 0 */ - /* USER CODE END UART4_Init 0 */ + /* USER CODE END USART2_Init 0 */ LL_USART_InitTypeDef USART_InitStruct = {0}; LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; /* Peripheral clock enable */ - LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UART4); + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2); LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); - LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOC); - /**UART4 GPIO Configuration - PA0/WKUP ------> UART4_TX - PC11 ------> UART4_RX + LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOD); + /**USART2 GPIO Configuration + PA3 ------> USART2_RX + PD5 ------> USART2_TX */ - GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Pin = LL_GPIO_PIN_3; GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_8; + GPIO_InitStruct.Alternate = LL_GPIO_AF_7; LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - GPIO_InitStruct.Pin = LL_GPIO_PIN_11; + GPIO_InitStruct.Pin = LL_GPIO_PIN_5; GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - GPIO_InitStruct.Alternate = LL_GPIO_AF_8; - LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + GPIO_InitStruct.Alternate = LL_GPIO_AF_7; + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - /* USER CODE BEGIN UART4_Init 1 */ + /* USER CODE BEGIN USART2_Init 1 */ - /* USER CODE END UART4_Init 1 */ + /* USER CODE END USART2_Init 1 */ USART_InitStruct.BaudRate = 115200; USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; USART_InitStruct.StopBits = LL_USART_STOPBITS_1; @@ -349,12 +348,12 @@ static void MX_UART4_Init(void) 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(UART4, &USART_InitStruct); - LL_USART_ConfigAsyncMode(UART4); - LL_USART_Enable(UART4); - /* USER CODE BEGIN UART4_Init 2 */ + LL_USART_Init(USART2, &USART_InitStruct); + LL_USART_ConfigAsyncMode(USART2); + LL_USART_Enable(USART2); + /* USER CODE BEGIN USART2_Init 2 */ - /* USER CODE END UART4_Init 2 */ + /* USER CODE END USART2_Init 2 */ } @@ -549,6 +548,12 @@ static void MX_GPIO_Init(void) LL_GPIO_Init(GPIOC, &GPIO_InitStruct); /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_0; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /**/ GPIO_InitStruct.Pin = RMII_REF_CLK_Pin; GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; @@ -567,12 +572,6 @@ static void MX_GPIO_Init(void) LL_GPIO_Init(RMII_MDIO_GPIO_Port, &GPIO_InitStruct); /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_3; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /**/ GPIO_InitStruct.Pin = LL_GPIO_PIN_4; GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; @@ -657,8 +656,8 @@ static void MX_GPIO_Init(void) /**/ GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; LL_GPIO_Init(GPIOF, &GPIO_InitStruct); /**/ @@ -723,9 +722,9 @@ static void MX_GPIO_Init(void) /**/ GPIO_InitStruct.Pin = LL_GPIO_PIN_14; - GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; - LL_GPIO_Init(GPIOF, &GPIO_InitStruct); + GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + LL_GPIO_Init(GPIOE, &GPIO_InitStruct); /**/ GPIO_InitStruct.Pin = LL_GPIO_PIN_15; @@ -820,7 +819,7 @@ static void MX_GPIO_Init(void) GPIO_InitStruct.Pin = LL_GPIO_PIN_14; GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOE, &GPIO_InitStruct); + LL_GPIO_Init(GPIOD, &GPIO_InitStruct); /**/ GPIO_InitStruct.Pin = LL_GPIO_PIN_15; @@ -904,6 +903,15 @@ static void MX_GPIO_Init(void) /**/ GPIO_InitStruct.Pin = LL_GPIO_PIN_10; + GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; + GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; + GPIO_InitStruct.Alternate = LL_GPIO_AF_8; + LL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /**/ + GPIO_InitStruct.Pin = LL_GPIO_PIN_11; GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; LL_GPIO_Init(GPIOC, &GPIO_InitStruct); @@ -945,12 +953,6 @@ static void MX_GPIO_Init(void) LL_GPIO_Init(GPIOD, &GPIO_InitStruct); /**/ - GPIO_InitStruct.Pin = LL_GPIO_PIN_5; - GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /**/ GPIO_InitStruct.Pin = LL_GPIO_PIN_6; GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; @@ -1002,7 +1004,7 @@ static void MX_GPIO_Init(void) GPIO_InitStruct.Pin = LL_GPIO_PIN_14; GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; - LL_GPIO_Init(GPIOD, &GPIO_InitStruct); + LL_GPIO_Init(GPIOG, &GPIO_InitStruct); /**/ GPIO_InitStruct.Pin = LL_GPIO_PIN_15; @@ -1112,3 +1114,4 @@ void assert_failed(uint8_t *file, uint32_t line) #endif /* USE_FULL_ASSERT */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + diff --git a/templates/f7/f7.ioc b/templates/f7/f7.ioc index 06bb58b..44d506e 100644 --- a/templates/f7/f7.ioc +++ b/templates/f7/f7.ioc @@ -13,23 +13,23 @@ Mcu.Name=STM32F746ZGTx Mcu.Package=LQFP144 Mcu.Pin0=PC13 Mcu.Pin1=PC14/OSC32_IN -Mcu.Pin10=PC4 -Mcu.Pin11=PC5 -Mcu.Pin12=PB0 -Mcu.Pin13=PB13 -Mcu.Pin14=PB14 -Mcu.Pin15=PD8 -Mcu.Pin16=PD9 -Mcu.Pin17=PG6 -Mcu.Pin18=PG7 -Mcu.Pin19=PA8 +Mcu.Pin10=PC5 +Mcu.Pin11=PB0 +Mcu.Pin12=PB13 +Mcu.Pin13=PB14 +Mcu.Pin14=PD8 +Mcu.Pin15=PD9 +Mcu.Pin16=PG6 +Mcu.Pin17=PG7 +Mcu.Pin18=PA8 +Mcu.Pin19=PA9 Mcu.Pin2=PC15/OSC32_OUT -Mcu.Pin20=PA9 -Mcu.Pin21=PA10 -Mcu.Pin22=PA11 -Mcu.Pin23=PA12 -Mcu.Pin24=PA13 -Mcu.Pin25=PA14 +Mcu.Pin20=PA10 +Mcu.Pin21=PA11 +Mcu.Pin22=PA12 +Mcu.Pin23=PA13 +Mcu.Pin24=PA14 +Mcu.Pin25=PC10 Mcu.Pin26=PC11 Mcu.Pin27=PG11 Mcu.Pin28=PG13 @@ -39,10 +39,10 @@ Mcu.Pin30=PB7 Mcu.Pin31=VP_SYS_VS_Systick Mcu.Pin4=PH1/OSC_OUT Mcu.Pin5=PC1 -Mcu.Pin6=PA0/WKUP -Mcu.Pin7=PA1 -Mcu.Pin8=PA2 -Mcu.Pin9=PA7 +Mcu.Pin6=PA1 +Mcu.Pin7=PA2 +Mcu.Pin8=PA7 +Mcu.Pin9=PC4 Mcu.PinsNb=32 Mcu.ThirdPartyNb=0 Mcu.UserConstants= @@ -59,8 +59,6 @@ NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:true\:false NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:true\:true NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false -PA0/WKUP.Mode=Asynchronous -PA0/WKUP.Signal=UART4_TX PA1.GPIOParameters=GPIO_Label PA1.GPIO_Label=RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] PA1.Locked=true @@ -131,6 +129,9 @@ PC1.GPIOParameters=GPIO_Label PC1.GPIO_Label=RMII_MDC [LAN8742A-CZ-TR_MDC] PC1.Locked=true PC1.Signal=ETH_MDC +PC10.Locked=true +PC10.Mode=Asynchronous +PC10.Signal=UART4_TX PC11.Mode=Asynchronous PC11.Signal=UART4_RX PC13.GPIOParameters=GPIO_Label diff --git a/templates/f7/flash.jlink b/templates/f7/flash.jlink new file mode 100644 index 0000000..34f514d --- /dev/null +++ b/templates/f7/flash.jlink @@ -0,0 +1,7 @@ +if SWD +speed 4000 +device STM32F746ZG +loadbin build/f7.bin 0x8000000 +r +g +exit diff --git a/templates/f7/middleware.py b/templates/f7/middleware.py index b42eef9..c5e3e1b 100755 --- a/templates/f7/middleware.py +++ b/templates/f7/middleware.py @@ -14,7 +14,8 @@ ser = serial.Serial('/dev/ttyUSB0', 115200) def flash(): pipe = subprocess.PIPE - p = subprocess.Popen(['stm32flash', 'build/f7.bin', '0x8000000'], stdout=sys.stderr, stdin=pipe) + p = subprocess.Popen(['JLinkExe', 'flash.jlink'], stdout=sys.stderr, stdin=pipe) + #p = subprocess.Popen(['stm32flash', 'build/f7.bin', '0x8000000'], stdout=sys.stderr, stdin=pipe) stdout, stderr = p.communicate("") def read(channel, l): -- libgit2 0.26.0