Commit ca3e26f9 by Enrico Pozzobon

useless

parent f3a795af
...@@ -28,7 +28,6 @@ extern "C" { ...@@ -28,7 +28,6 @@ extern "C" {
#endif #endif
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f7xx_hal.h"
#include "stm32f7xx_ll_rcc.h" #include "stm32f7xx_ll_rcc.h"
#include "stm32f7xx_ll_bus.h" #include "stm32f7xx_ll_bus.h"
#include "stm32f7xx_ll_system.h" #include "stm32f7xx_ll_system.h"
...@@ -41,6 +40,10 @@ extern "C" { ...@@ -41,6 +40,10 @@ extern "C" {
#include "stm32f7xx.h" #include "stm32f7xx.h"
#include "stm32f7xx_ll_gpio.h" #include "stm32f7xx_ll_gpio.h"
#if defined(USE_FULL_ASSERT)
#include "stm32_assert.h"
#endif /* USE_FULL_ASSERT */
/* Private includes ----------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
...@@ -121,6 +124,18 @@ void Error_Handler(void); ...@@ -121,6 +124,18 @@ void Error_Handler(void);
#define SW0_GPIO_Port GPIOB #define SW0_GPIO_Port GPIOB
#define LD2_Pin LL_GPIO_PIN_7 #define LD2_Pin LL_GPIO_PIN_7
#define LD2_GPIO_Port GPIOB #define LD2_GPIO_Port GPIOB
#ifndef NVIC_PRIORITYGROUP_0
#define NVIC_PRIORITYGROUP_0 ((uint32_t)0x00000007) /*!< 0 bit for pre-emption priority,
4 bits for subpriority */
#define NVIC_PRIORITYGROUP_1 ((uint32_t)0x00000006) /*!< 1 bit for pre-emption priority,
3 bits for subpriority */
#define NVIC_PRIORITYGROUP_2 ((uint32_t)0x00000005) /*!< 2 bits for pre-emption priority,
2 bits for subpriority */
#define NVIC_PRIORITYGROUP_3 ((uint32_t)0x00000004) /*!< 3 bits for pre-emption priority,
1 bit for subpriority */
#define NVIC_PRIORITYGROUP_4 ((uint32_t)0x00000003) /*!< 4 bits for pre-emption priority,
0 bit for subpriority */
#endif
/* USER CODE BEGIN Private defines */ /* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */ /* USER CODE END Private defines */
......
#pragma once
void test_setup();
void test_loop();
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void uartp_send(const void *src, uint16_t len);
uint16_t uartp_recv(void *dst, uint16_t buf_len);
#ifdef __cplusplus
}
#endif
########################################################################################################################## ##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.3.0] date: [Sun Jul 14 11:29:48 CEST 2019] # File automatically-generated by tool: [projectgenerator] version: [3.4.0] date: [Sun Jul 21 14:48:38 CEST 2019]
########################################################################################################################## ##########################################################################################################################
# ------------------------------------------------ # ------------------------------------------------
...@@ -38,23 +38,18 @@ BUILD_DIR = build ...@@ -38,23 +38,18 @@ BUILD_DIR = build
C_SOURCES = \ C_SOURCES = \
Src/main.c \ Src/main.c \
Src/stm32f7xx_it.c \ Src/stm32f7xx_it.c \
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_cortex.c \
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal.c \
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_tim.c \
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_tim_ex.c \
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_gpio.c \ Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_gpio.c \
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_cortex.c \
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usart.c \ Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usart.c \
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_dma.c \ Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_dma.c \
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.c \
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_rcc.c \ Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_rcc.c \
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_utils.c \ Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_utils.c \
Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_exti.c \ Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_exti.c \
Src/system_stm32f7xx.c \ Src/system_stm32f7xx.c \
Src/RTT/SEGGER_RTT.c \ Src/test.c \
Src/RTT/SEGGER_RTT_printf.c \ Src/uartp.c \
$(SRC_FILES) $(SRC_FILES)
# ASM sources # ASM sources
ASM_SOURCES = \ ASM_SOURCES = \
startup_stm32f746xx.s startup_stm32f746xx.s
...@@ -102,11 +97,28 @@ AS_DEFS = ...@@ -102,11 +97,28 @@ AS_DEFS =
# C defines # C defines
C_DEFS = \ C_DEFS = \
-DUSE_FULL_LL_DRIVER \ -DUSE_FULL_LL_DRIVER \
-DUSE_HAL_DRIVER \ -DHSE_VALUE=8000000 \
-DHSE_STARTUP_TIMEOUT=100 \
-DLSE_STARTUP_TIMEOUT=5000 \
-DLSE_VALUE=32768 \
-DEXTERNAL_CLOCK_VALUE=12288000 \
-DHSI_VALUE=16000000 \
-DLSI_VALUE=32000 \
-DVDD_VALUE=3300 \
-DPREFETCH_ENABLE=0 \
-DART_ACCLERATOR_ENABLE=0 \
-DSTM32F746xx \ -DSTM32F746xx \
-DUSE_FULL_LL_DRIVER \ -DUSE_FULL_LL_DRIVER \
-DUSE_HAL_DRIVER \ -DHSE_VALUE=8000000 \
-DUSE_HAL_DRIVER \ -DHSE_STARTUP_TIMEOUT=100 \
-DLSE_STARTUP_TIMEOUT=5000 \
-DLSE_VALUE=32768 \
-DEXTERNAL_CLOCK_VALUE=12288000 \
-DHSI_VALUE=16000000 \
-DLSI_VALUE=32000 \
-DVDD_VALUE=3300 \
-DPREFETCH_ENABLE=0 \
-DART_ACCLERATOR_ENABLE=0 \
-DSTM32F746xx -DSTM32F746xx
...@@ -117,7 +129,6 @@ AS_INCLUDES = ...@@ -117,7 +129,6 @@ AS_INCLUDES =
C_INCLUDES = \ C_INCLUDES = \
-IInc \ -IInc \
-IDrivers/STM32F7xx_HAL_Driver/Inc \ -IDrivers/STM32F7xx_HAL_Driver/Inc \
-IDrivers/STM32F7xx_HAL_Driver/Inc/Legacy \
-IDrivers/CMSIS/Device/ST/STM32F7xx/Include \ -IDrivers/CMSIS/Device/ST/STM32F7xx/Include \
-IDrivers/CMSIS/Include \ -IDrivers/CMSIS/Include \
-IDrivers/CMSIS/Include -IDrivers/CMSIS/Include
......
/* USER CODE BEGIN Header */
/**
******************************************************************************
* File Name : stm32f7xx_hal_msp.c
* Description : This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN Define */
/* USER CODE END Define */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN Macro */
/* USER CODE END Macro */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* External functions --------------------------------------------------------*/
/* USER CODE BEGIN ExternalFunctions */
/* USER CODE END ExternalFunctions */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_RCC_SYSCFG_CLK_ENABLE();
/* System interrupt init*/
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
/**
* @brief PCD MSP Initialization
* This function configures the hardware resources used in this example
* @param hpcd: PCD handle pointer
* @retval None
*/
void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(hpcd->Instance==USB_OTG_FS)
{
/* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
/* USER CODE END USB_OTG_FS_MspInit 0 */
__HAL_RCC_GPIOA_CLK_ENABLE();
/**USB_OTG_FS GPIO Configuration
PA8 ------> USB_OTG_FS_SOF
PA9 ------> USB_OTG_FS_VBUS
PA10 ------> USB_OTG_FS_ID
PA11 ------> USB_OTG_FS_DM
PA12 ------> USB_OTG_FS_DP
*/
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Peripheral clock enable */
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
/* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
/* USER CODE END USB_OTG_FS_MspInit 1 */
}
}
/**
* @brief PCD MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hpcd: PCD handle pointer
* @retval None
*/
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
{
if(hpcd->Instance==USB_OTG_FS)
{
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
/* USER CODE END USB_OTG_FS_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USB_OTG_FS_CLK_DISABLE();
/**USB_OTG_FS GPIO Configuration
PA8 ------> USB_OTG_FS_SOF
PA9 ------> USB_OTG_FS_VBUS
PA10 ------> USB_OTG_FS_ID
PA11 ------> USB_OTG_FS_DM
PA12 ------> USB_OTG_FS_DP
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
|GPIO_PIN_12);
/* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
/* USER CODE END USB_OTG_FS_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
...@@ -184,7 +184,7 @@ void SysTick_Handler(void) ...@@ -184,7 +184,7 @@ void SysTick_Handler(void)
/* USER CODE BEGIN SysTick_IRQn 0 */ /* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */ /* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
/* USER CODE BEGIN SysTick_IRQn 1 */ /* USER CODE BEGIN SysTick_IRQn 1 */
/* USER CODE END SysTick_IRQn 1 */ /* USER CODE END SysTick_IRQn 1 */
......
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdarg.h>
#include "crypto_aead.h"
#include "api.h"
#include "uartp.h"
#include "main.h"
#define MAX_BYTES 100
//#define DEBUG
#define CRYPTO_BUSY_GPIO_Port LD1_GPIO_Port
#define CRYPTO_BUSY_Pin LD1_Pin
uint8_t npub[CRYPTO_NPUBBYTES];
uint8_t nsec[CRYPTO_NSECBYTES];
uint8_t k[CRYPTO_KEYBYTES];
uint8_t ad[MAX_BYTES];
unsigned long long int adlen;
uint8_t m[MAX_BYTES];
unsigned long long int mlen;
uint8_t c[MAX_BYTES];
unsigned long long int clen;
int res;
void setup();
void loop();
void uart_wbyte(uint8_t x) {
while (!LL_USART_IsActiveFlag_TXE(USART2));
LL_USART_TransmitData8(USART2, x);
}
uint8_t uart_rbyte() {
while (!LL_USART_IsActiveFlag_RXNE(USART2));
uint8_t r = (uint8_t) LL_USART_ReceiveData8(USART2);
LL_USART_TransmitData8(USART2, r);
return r;
}
static inline void noInterrupts() {
// TODO: if necessary, provide a way to disable interrupts
}
static inline void interrupts() {
// TODO: if necessary, provide a way to enable interrupts
}
int dbg_printf(const char *format, ...) {
int r = 0;
#ifdef DEBUG
#define DEBUG_BUF_LEN 80
char printbuf[DEBUG_BUF_LEN+2];
va_list vargs;
va_start(vargs, format);
r = vsnprintf(printbuf+1, DEBUG_BUF_LEN, format, vargs);
va_end(vargs);
if (r < 0) {
memcpy(printbuf+1, "DEBUG ERROR\r\n", 13);
r = 13;
}
r = r > DEBUG_BUF_LEN ? DEBUG_BUF_LEN : r;
printbuf[0] = 0xde; // Debug messages should start with "\xde"
uartp_send(printbuf, r+1);
#endif
return r;
}
void my_assert(bool b) {
if (b)
return;
dbg_printf("Assertion failed\r\n");
Error_Handler();
for(;;);
}
void test_setup() {
LL_GPIO_SetOutputPin(CRYPTO_BUSY_GPIO_Port, CRYPTO_BUSY_Pin);
LL_mDelay(100);
for (int i = 0; i < 13; i++) {
uart_wbyte("Hello, World!"[i]);
}
LL_USART_ReceiveData8(USART2);
}
void test_loop() {
uart_rbyte();
return;
static uint8_t buf[256];
uint16_t len = uartp_recv(buf, 255);
uint8_t action = buf[0];
if (len == 0 || len > 255)
return;
uint16_t l = len - 1;
uint16_t rl = 0;
uint8_t *var = buf+1;
switch (action) {
case 'm': my_assert(l <= MAX_BYTES); memcpy(m, var, l); mlen = l; break;
case 'c': my_assert(l <= MAX_BYTES); memcpy(c, var, l); clen = l; break;
case 'a': my_assert(l <= MAX_BYTES); memcpy(ad, var, l); adlen = l; break;
case 'k': my_assert(l == CRYPTO_KEYBYTES); memcpy(k, var, l); break;
case 'p': my_assert(l == CRYPTO_NPUBBYTES); memcpy(npub, var, l); break;
case 's': my_assert(l == CRYPTO_NSECBYTES); memcpy(nsec, var, l); break;
case 'e':
noInterrupts();
asm("nop");
LL_GPIO_ResetOutputPin(CRYPTO_BUSY_GPIO_Port, CRYPTO_BUSY_Pin);
res = crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k);
LL_GPIO_SetOutputPin(CRYPTO_BUSY_GPIO_Port, CRYPTO_BUSY_Pin);
asm("nop");
interrupts();
break;
case 'd':
noInterrupts();
asm("nop");
LL_GPIO_ResetOutputPin(CRYPTO_BUSY_GPIO_Port, CRYPTO_BUSY_Pin);
res = crypto_aead_decrypt(m, &mlen, nsec, c, clen, ad, adlen, npub, k);
LL_GPIO_SetOutputPin(CRYPTO_BUSY_GPIO_Port, CRYPTO_BUSY_Pin);
asm("nop");
interrupts();
break;
case'M': var = m; rl = mlen; break;
case'C': var = c; rl = clen; break;
case'A': var = ad; rl = adlen; break;
case'K': var = k; rl = CRYPTO_KEYBYTES; break;
case'P': var = npub; rl = CRYPTO_NPUBBYTES; break;
case'S': var = nsec; rl = CRYPTO_NSECBYTES; break;
case'R': var = (uint8_t *) &res; rl = sizeof(res); break;
default:
dbg_printf("Unknown command\r\n");
my_assert(false);
}
buf[0] = action;
memcpy(buf+1, var, rl);
uartp_send(buf, rl+1);
}
#include <stdint.h>
#include "uartp.h"
extern void uart_wbyte(uint8_t x);
extern uint8_t uart_rbyte();
// Simple serial protocol with packets and checksum
const uint8_t AMUX_TAG = 0xf9;
const uint8_t AMUX_END = 0xf3;
const uint8_t AMUX_EXT = 0x80;
void uartp_send(const void *src, uint16_t len) {
uint8_t len_ind_0, len_ind_1, fcs, info;
const uint8_t *buf = (const uint8_t *) src;
uart_wbyte(AMUX_TAG);
len_ind_0 = (uint8_t) (0xff & len);
len_ind_1 = (uint8_t) (0xff & (len >> 7));
if (len < 128) {
uart_wbyte(len_ind_0);
} else {
uart_wbyte(len_ind_0 | AMUX_EXT);
uart_wbyte(len_ind_1);
}
fcs = 0;
for (uint16_t i = 0; i < len; i++) {
info = buf[i];
fcs += info;
uart_wbyte(buf[i]);
}
fcs = 255 - fcs;
uart_wbyte(fcs);
uart_wbyte(AMUX_END);
}
uint16_t uartp_recv(void *dst, uint16_t buf_len) {
uint8_t *buf = (uint8_t *) dst;
uint8_t tag_old, tag, info, cs;
uint16_t len;
tag = AMUX_END;
while (1) {
do {
tag_old = tag;
tag = uart_rbyte();
} while(tag != AMUX_TAG || tag_old != AMUX_END);
len = (uint16_t) uart_rbyte();
if (len & AMUX_EXT) {
len &= (~AMUX_EXT);
len |= (uint16_t) (uart_rbyte() << 7);
}
if (len > buf_len) {
return len;
}
uint16_t i = 0;
cs = 0;
for (i = 0; i < len; i++) {
info = uart_rbyte();
buf[i] = info;
cs += info;
}
cs += uart_rbyte();
tag = uart_rbyte();
if (0xff == cs) {
if (AMUX_END == tag) {
return len;
}
}
}
}
#!/bin/bash #!/bin/bash
mv -n *.inc *.h Inc/
mv $HDR_FILES Inc/ sed -i src/encrypt.c -e "s/\(\s\)init(/\1_init(/g"
mv "middleware.py" "test" exit 0
int crypto_aead_encrypt(
unsigned char *c,unsigned long long *clen,
const unsigned char *m,unsigned long long mlen,
const unsigned char *ad,unsigned long long adlen,
const unsigned char *nsec,
const unsigned char *npub,
const unsigned char *k
);
int crypto_aead_decrypt(
unsigned char *m,unsigned long long *outputmlen,
unsigned char *nsec,
const unsigned char *c,unsigned long long clen,
const unsigned char *ad,unsigned long long adlen,
const unsigned char *npub,
const unsigned char *k
);
...@@ -6,31 +6,31 @@ Mcu.IP0=CORTEX_M7 ...@@ -6,31 +6,31 @@ Mcu.IP0=CORTEX_M7
Mcu.IP1=NVIC Mcu.IP1=NVIC
Mcu.IP2=RCC Mcu.IP2=RCC
Mcu.IP3=SYS Mcu.IP3=SYS
Mcu.IP4=UART4 Mcu.IP4=USART2
Mcu.IP5=USB_OTG_FS Mcu.IP5=USART3
Mcu.IPNb=6 Mcu.IPNb=6
Mcu.Name=STM32F746ZGTx Mcu.Name=STM32F746ZGTx
Mcu.Package=LQFP144 Mcu.Package=LQFP144
Mcu.Pin0=PC13 Mcu.Pin0=PC13
Mcu.Pin1=PC14/OSC32_IN Mcu.Pin1=PC14/OSC32_IN
Mcu.Pin10=PC5 Mcu.Pin10=PC4
Mcu.Pin11=PB0 Mcu.Pin11=PC5
Mcu.Pin12=PB13 Mcu.Pin12=PB0
Mcu.Pin13=PB14 Mcu.Pin13=PB13
Mcu.Pin14=PD8 Mcu.Pin14=PB14
Mcu.Pin15=PD9 Mcu.Pin15=PD8
Mcu.Pin16=PG6 Mcu.Pin16=PD9
Mcu.Pin17=PG7 Mcu.Pin17=PG6
Mcu.Pin18=PA8 Mcu.Pin18=PG7
Mcu.Pin19=PA9 Mcu.Pin19=PA8
Mcu.Pin2=PC15/OSC32_OUT Mcu.Pin2=PC15/OSC32_OUT
Mcu.Pin20=PA10 Mcu.Pin20=PA9
Mcu.Pin21=PA11 Mcu.Pin21=PA10
Mcu.Pin22=PA12 Mcu.Pin22=PA11
Mcu.Pin23=PA13 Mcu.Pin23=PA12
Mcu.Pin24=PA14 Mcu.Pin24=PA13
Mcu.Pin25=PC10 Mcu.Pin25=PA14
Mcu.Pin26=PC11 Mcu.Pin26=PD5
Mcu.Pin27=PG11 Mcu.Pin27=PG11
Mcu.Pin28=PG13 Mcu.Pin28=PG13
Mcu.Pin29=PB3 Mcu.Pin29=PB3
...@@ -41,14 +41,14 @@ Mcu.Pin4=PH1/OSC_OUT ...@@ -41,14 +41,14 @@ Mcu.Pin4=PH1/OSC_OUT
Mcu.Pin5=PC1 Mcu.Pin5=PC1
Mcu.Pin6=PA1 Mcu.Pin6=PA1
Mcu.Pin7=PA2 Mcu.Pin7=PA2
Mcu.Pin8=PA7 Mcu.Pin8=PA3
Mcu.Pin9=PC4 Mcu.Pin9=PA7
Mcu.PinsNb=32 Mcu.PinsNb=32
Mcu.ThirdPartyNb=0 Mcu.ThirdPartyNb=0
Mcu.UserConstants= Mcu.UserConstants=
Mcu.UserName=STM32F746ZGTx Mcu.UserName=STM32F746ZGTx
MxCube.Version=5.2.1 MxCube.Version=5.3.0
MxDb.Version=DB.5.0.21 MxDb.Version=DB.5.0.30
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:true\:false NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:true\:false
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false
...@@ -70,12 +70,10 @@ PA10.Signal=USB_OTG_FS_ID ...@@ -70,12 +70,10 @@ PA10.Signal=USB_OTG_FS_ID
PA11.GPIOParameters=GPIO_Label PA11.GPIOParameters=GPIO_Label
PA11.GPIO_Label=USB_DM PA11.GPIO_Label=USB_DM
PA11.Locked=true PA11.Locked=true
PA11.Mode=Device_Only
PA11.Signal=USB_OTG_FS_DM PA11.Signal=USB_OTG_FS_DM
PA12.GPIOParameters=GPIO_Label PA12.GPIOParameters=GPIO_Label
PA12.GPIO_Label=USB_DP PA12.GPIO_Label=USB_DP
PA12.Locked=true PA12.Locked=true
PA12.Mode=Device_Only
PA12.Signal=USB_OTG_FS_DP PA12.Signal=USB_OTG_FS_DP
PA13.GPIOParameters=GPIO_Label PA13.GPIOParameters=GPIO_Label
PA13.GPIO_Label=TMS PA13.GPIO_Label=TMS
...@@ -91,6 +89,8 @@ PA2.GPIOParameters=GPIO_Label ...@@ -91,6 +89,8 @@ PA2.GPIOParameters=GPIO_Label
PA2.GPIO_Label=RMII_MDIO [LAN8742A-CZ-TR_MDIO] PA2.GPIO_Label=RMII_MDIO [LAN8742A-CZ-TR_MDIO]
PA2.Locked=true PA2.Locked=true
PA2.Signal=ETH_MDIO PA2.Signal=ETH_MDIO
PA3.Mode=Asynchronous
PA3.Signal=USART2_RX
PA7.GPIOParameters=GPIO_Label PA7.GPIOParameters=GPIO_Label
PA7.GPIO_Label=RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] PA7.GPIO_Label=RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV]
PA7.Locked=true PA7.Locked=true
...@@ -98,12 +98,10 @@ PA7.Signal=ETH_CRS_DV ...@@ -98,12 +98,10 @@ PA7.Signal=ETH_CRS_DV
PA8.GPIOParameters=GPIO_Label PA8.GPIOParameters=GPIO_Label
PA8.GPIO_Label=USB_SOF [TP1] PA8.GPIO_Label=USB_SOF [TP1]
PA8.Locked=true PA8.Locked=true
PA8.Mode=Activate_SOF_FS
PA8.Signal=USB_OTG_FS_SOF PA8.Signal=USB_OTG_FS_SOF
PA9.GPIOParameters=GPIO_Label PA9.GPIOParameters=GPIO_Label
PA9.GPIO_Label=USB_VBUS PA9.GPIO_Label=USB_VBUS
PA9.Locked=true PA9.Locked=true
PA9.Mode=Activate_VBUS
PA9.Signal=USB_OTG_FS_VBUS PA9.Signal=USB_OTG_FS_VBUS
PB0.GPIOParameters=GPIO_Label PB0.GPIOParameters=GPIO_Label
PB0.GPIO_Label=LD1 [Green] PB0.GPIO_Label=LD1 [Green]
...@@ -129,11 +127,6 @@ PC1.GPIOParameters=GPIO_Label ...@@ -129,11 +127,6 @@ PC1.GPIOParameters=GPIO_Label
PC1.GPIO_Label=RMII_MDC [LAN8742A-CZ-TR_MDC] PC1.GPIO_Label=RMII_MDC [LAN8742A-CZ-TR_MDC]
PC1.Locked=true PC1.Locked=true
PC1.Signal=ETH_MDC 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 PC13.GPIOParameters=GPIO_Label
PC13.GPIO_Label=USER_Btn [B1] PC13.GPIO_Label=USER_Btn [B1]
PC13.Locked=true PC13.Locked=true
...@@ -160,13 +153,17 @@ PCC.Seq0=0 ...@@ -160,13 +153,17 @@ PCC.Seq0=0
PCC.Series=STM32F7 PCC.Series=STM32F7
PCC.Temperature=25 PCC.Temperature=25
PCC.Vdd=3.6 PCC.Vdd=3.6
PD5.Mode=Asynchronous
PD5.Signal=USART2_TX
PD8.GPIOParameters=GPIO_Label PD8.GPIOParameters=GPIO_Label
PD8.GPIO_Label=STLK_RX [STM32F103CBT6_PA3] PD8.GPIO_Label=STLK_RX [STM32F103CBT6_PA3]
PD8.Locked=true PD8.Locked=true
PD8.Mode=Asynchronous
PD8.Signal=USART3_TX PD8.Signal=USART3_TX
PD9.GPIOParameters=GPIO_Label PD9.GPIOParameters=GPIO_Label
PD9.GPIO_Label=STLK_TX [STM32F103CBT6_PA2] PD9.GPIO_Label=STLK_TX [STM32F103CBT6_PA2]
PD9.Locked=true PD9.Locked=true
PD9.Mode=Asynchronous
PD9.Signal=USART3_RX PD9.Signal=USART3_RX
PG11.GPIOParameters=GPIO_Label PG11.GPIOParameters=GPIO_Label
PG11.GPIO_Label=RMII_TX_EN [LAN8742A-CZ-TR_TXEN] PG11.GPIO_Label=RMII_TX_EN [LAN8742A-CZ-TR_TXEN]
...@@ -203,12 +200,12 @@ ProjectManager.DefaultFWLocation=true ...@@ -203,12 +200,12 @@ ProjectManager.DefaultFWLocation=true
ProjectManager.DeletePrevious=true ProjectManager.DeletePrevious=true
ProjectManager.DeviceId=STM32F746ZGTx ProjectManager.DeviceId=STM32F746ZGTx
ProjectManager.FirmwarePackage=STM32Cube FW_F7 V1.15.0 ProjectManager.FirmwarePackage=STM32Cube FW_F7 V1.15.0
ProjectManager.FreePins=true ProjectManager.FreePins=false
ProjectManager.HalAssertFull=false ProjectManager.HalAssertFull=false
ProjectManager.HeapSize=0x200 ProjectManager.HeapSize=0x200
ProjectManager.KeepUserCode=true ProjectManager.KeepUserCode=true
ProjectManager.LastFirmware=true ProjectManager.LastFirmware=true
ProjectManager.LibraryCopy=1 ProjectManager.LibraryCopy=0
ProjectManager.MainLocation=Src ProjectManager.MainLocation=Src
ProjectManager.NoMain=false ProjectManager.NoMain=false
ProjectManager.PreviousToolchain= ProjectManager.PreviousToolchain=
...@@ -219,7 +216,7 @@ ProjectManager.StackSize=0x400 ...@@ -219,7 +216,7 @@ ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=Makefile ProjectManager.TargetToolchain=Makefile
ProjectManager.ToolChainLocation= ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=false ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-LL-true,2-SystemClock_Config-RCC-false-LL-false,3-MX_USB_OTG_FS_PCD_Init-USB_OTG_FS-false-HAL-true,4-MX_UART4_Init-UART4-false-LL-true ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-LL-true,2-SystemClock_Config-RCC-false-LL-false,3-MX_UART4_Init-UART4-false-LL-true,3-MX_USART2_UART_Init-USART2-false-LL-true,4-MX_USART3_UART_Init-USART3-false-LL-true
RCC.48MHZClocksFreq_Value=24000000 RCC.48MHZClocksFreq_Value=24000000
RCC.ADC12outputFreq_Value=72000000 RCC.ADC12outputFreq_Value=72000000
RCC.ADC34outputFreq_Value=72000000 RCC.ADC34outputFreq_Value=72000000
...@@ -243,7 +240,7 @@ RCC.I2C3Freq_Value=36000000 ...@@ -243,7 +240,7 @@ RCC.I2C3Freq_Value=36000000
RCC.I2C4Freq_Value=36000000 RCC.I2C4Freq_Value=36000000
RCC.I2SClocksFreq_Value=48000000 RCC.I2SClocksFreq_Value=48000000
RCC.I2SFreq_Value=192000000 RCC.I2SFreq_Value=192000000
RCC.IPParameters=48MHZClocksFreq_Value,ADC12outputFreq_Value,ADC34outputFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CECFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SClocksFreq_Value,I2SFreq_Value,LCDTFToutputFreq_Value,LPTIM1Freq_Value,LSI_VALUE,MCO1PinFreq_Value,MCO2PinFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLI2SPCLKFreq_Value,PLLI2SQCLKFreq_Value,PLLI2SRCLKFreq_Value,PLLI2SRoutputFreq_Value,PLLM,PLLMCOFreq_Value,PLLMUL,PLLN,PLLQ,PLLQCLKFreq_Value,PLLQoutputFreq_Value,PLLSAIPCLKFreq_Value,PLLSAIQCLKFreq_Value,PLLSAIRCLKFreq_Value,PLLSAIoutputFreq_Value,PRESCALERUSB,RNGFreq_Value,RTCFreq_Value,RTCHSEDivFreq_Value,SAI1Freq_Value,SAI2Freq_Value,SDMMCFreq_Value,SPDIFRXFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,SYSCLKSourceVirtual,TIM15Freq_Value,TIM16Freq_Value,TIM17Freq_Value,TIM1Freq_Value,TIM20Freq_Value,TIM2Freq_Value,TIM3Freq_Value,TIM8Freq_Value,UART4Freq_Value,UART5Freq_Value,UART7Freq_Value,UART8Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USART6Freq_Value,USBFreq_Value,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutput2Freq_Value,VCOOutputFreq_Value,VCOSAIOutputFreq_Value,VcooutputI2S,WatchDogFreq_Value RCC.IPParameters=48MHZClocksFreq_Value,ADC12outputFreq_Value,ADC34outputFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CECFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SClocksFreq_Value,I2SFreq_Value,LCDTFToutputFreq_Value,LPTIM1Freq_Value,LSI_VALUE,MCO1PinFreq_Value,MCO2PinFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLI2SPCLKFreq_Value,PLLI2SQCLKFreq_Value,PLLI2SRCLKFreq_Value,PLLI2SRoutputFreq_Value,PLLM,PLLMCOFreq_Value,PLLMUL,PLLN,PLLQ,PLLQCLKFreq_Value,PLLQoutputFreq_Value,PLLSAIPCLKFreq_Value,PLLSAIQCLKFreq_Value,PLLSAIRCLKFreq_Value,PLLSAIoutputFreq_Value,PLLSourceVirtual,PRESCALERUSB,RNGFreq_Value,RTCFreq_Value,RTCHSEDivFreq_Value,SAI1Freq_Value,SAI2Freq_Value,SDMMCFreq_Value,SPDIFRXFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,SYSCLKSourceVirtual,TIM15Freq_Value,TIM16Freq_Value,TIM17Freq_Value,TIM1Freq_Value,TIM20Freq_Value,TIM2Freq_Value,TIM3Freq_Value,TIM8Freq_Value,UART4Freq_Value,UART5Freq_Value,UART7Freq_Value,UART8Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USART6Freq_Value,USBFreq_Value,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutput2Freq_Value,VCOOutputFreq_Value,VCOSAIOutputFreq_Value,VcooutputI2S,WatchDogFreq_Value
RCC.LCDTFToutputFreq_Value=96000000 RCC.LCDTFToutputFreq_Value=96000000
RCC.LPTIM1Freq_Value=36000000 RCC.LPTIM1Freq_Value=36000000
RCC.LSI_VALUE=32000 RCC.LSI_VALUE=32000
...@@ -266,6 +263,7 @@ RCC.PLLSAIPCLKFreq_Value=192000000 ...@@ -266,6 +263,7 @@ RCC.PLLSAIPCLKFreq_Value=192000000
RCC.PLLSAIQCLKFreq_Value=192000000 RCC.PLLSAIQCLKFreq_Value=192000000
RCC.PLLSAIRCLKFreq_Value=192000000 RCC.PLLSAIRCLKFreq_Value=192000000
RCC.PLLSAIoutputFreq_Value=192000000 RCC.PLLSAIoutputFreq_Value=192000000
RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
RCC.PRESCALERUSB=RCC_USBCLKSOURCE_PLL_DIV1_5 RCC.PRESCALERUSB=RCC_USBCLKSOURCE_PLL_DIV1_5
RCC.RNGFreq_Value=48000000 RCC.RNGFreq_Value=48000000
RCC.RTCFreq_Value=32000 RCC.RTCFreq_Value=32000
...@@ -303,8 +301,10 @@ RCC.VcooutputI2S=48000000 ...@@ -303,8 +301,10 @@ RCC.VcooutputI2S=48000000
RCC.WatchDogFreq_Value=32000 RCC.WatchDogFreq_Value=32000
SH.GPXTI13.0=GPIO_EXTI13 SH.GPXTI13.0=GPIO_EXTI13
SH.GPXTI13.ConfNb=1 SH.GPXTI13.ConfNb=1
USB_OTG_FS.IPParameters=VirtualMode USART2.IPParameters=VirtualMode-Asynchronous
USB_OTG_FS.VirtualMode=Device_Only USART2.VirtualMode-Asynchronous=VM_ASYNC
USART3.IPParameters=VirtualMode-Asynchronous
USART3.VirtualMode-Asynchronous=VM_ASYNC
VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick VP_SYS_VS_Systick.Signal=SYS_VS_Systick
board=NUCLEO-F746ZG board=NUCLEO-F746ZG
......
#!/usr/bin/python3 -u
import os
import sys
import time
import struct
import serial
import subprocess
DBG=''
ser = serial.Serial('/dev/ttyUSB0', 115200)
def flash():
pipe = subprocess.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):
if channel == 'ser':
data = ser.read(l)
elif channel == 'std':
data = sys.stdin.buffer.read(l)
else:
raise Exception("read() complains: no sai channelino")
if len(data) != l:
raise Exception("could not read %d bytes of data (got %d)" % (l, len(data)))
return data
def write(channel, data):
if channel == 'ser':
l = ser.write(data)
if DBG:
print("Data sent to serial: " + str(data) + "\n", file=sys.stderr)
elif channel == 'std':
l = sys.stdout.buffer.write(data)
else:
raise Exception("write() complains: no sai channelino")
if len(data) != l:
raise Exception("could not write %d bytes of data (put %d)" % (len(data), l))
def obtain(channel):
l = read(channel, 4)
(l, ) = struct.unpack("<I", l)
if DBG:
print("Trying to read %d bytes from %s\n" % (l, channel), file=sys.stderr)
return read(channel, l)
def submit(channel, action, data):
if channel == "std":
h = struct.pack("<I", len(data))
else:
h = struct.pack("<BI", ord(action), len(data))
write(channel, h)
write(channel, data)
time.sleep(0.1)
def main(argv):
if DBG:
print(argv[0], file=sys.stderr)
script_dir = os.path.split(argv[0])[0]
if len(script_dir ) > 0:
os.chdir(script_dir)
flash()
print("Hello, World!")
while(1):
action = read('std', 1)
if DBG:
print("Read following action from stdin: %s\n" % action, file=sys.stderr)
if action == b'c' or action == b'm' or action == b'a' or action == b'k' or action == b's' or action == b'p':
data = obtain('std')
submit('ser', action, data)
elif action == b'e' or action == b'd':
write('ser', action)
elif action == b'C' or action == b'M' or action == b'A' or action == b'K' or action == b'S' or action == b'P':
write('ser', action)
data = obtain('ser')
if DBG:
print("Obtained following data from serial: %s\n" % data, file=sys.stderr)
submit('std', action, data)
if DBG:
print("Submitted following data to stdout: %s\n" % data, file=sys.stderr)
else:
raise Exception("no capiche aczione %s" % (action))
if __name__ == "__main__":
sys.exit(main(sys.argv))
#!/usr/bin/env python3
import os
import sys
import time
import struct
import serial
import subprocess
def eprint(*args, **kargs):
print(*args, file=sys.stderr, **kargs)
def flash():
pipe = subprocess.PIPE
cmd = ['JLinkExe', 'flash.jlink']
p = subprocess.Popen(cmd,
stdout=sys.stderr, stdin=pipe)
stdout, stderr = p.communicate("")
def get_serial():
import serial.tools.list_ports
ports = serial.tools.list_ports.comports()
devices = [ p.device for p in ports ]
devices.sort()
return devices[-1]
class UARTP:
def __init__(self, ser):
UARTP.SYN = 0xf9
UARTP.FIN = 0xf3
self.ser = ser
def uart_read(self):
r = self.ser.read(1)
if len(r) != 1:
raise Exception("Serial read error")
return r[0]
def uart_write(self, c):
b = struct.pack("B", c)
r = self.ser.write(b)
if r != len(b):
raise Exception("Serial write error")
return r
def send(self, buf):
self.uart_write(UARTP.SYN)
len_ind_0 = 0xff & len(buf)
len_ind_1 = 0xff & (len(buf) >> 7)
if len(buf) < 128:
self.uart_write(len_ind_0)
else:
self.uart_write(len_ind_0 | 0x80)
self.uart_write(len_ind_1)
fcs = 0
for i in range(len(buf)):
info = buf[i]
fcs = (fcs + info) & 0xff
self.uart_write(buf[i])
fcs = (0xff - fcs) & 0xff
self.uart_write(fcs)
self.uart_write(UARTP.FIN)
eprint("sent frame '%s'" % buf.hex())
def recv(self):
tag_old = UARTP.FIN
while 1:
tag = tag_old
while 1:
if tag_old == UARTP.FIN:
if tag == UARTP.SYN:
break
tag_old = tag
tag = self.uart_read()
tag_old = tag
l = self.uart_read()
if l & 0x80:
l &= 0x7f
l |= self.uart_read() << 7
fcs = 0
buf = []
for i in range(l):
info = self.uart_read()
buf.append(info)
fcs = (fcs + info) & 0xff
fcs = (fcs + self.uart_read()) & 0xff
tag = self.uart_read()
if fcs == 0xff:
if tag == UARTP.FIN:
buf = bytes(buf)
eprint("rcvd frame '%s'" % buf.hex())
if len(buf) >= 1 and buf[0] == 0xde:
sys.stderr.buffer.write(buf[1:])
sys.stderr.flush()
else:
return buf
def main(argv):
eprint(argv[0])
script_dir = os.path.split(argv[0])[0]
if len(script_dir) > 0:
os.chdir(script_dir)
dev = get_serial()
ser = serial.Serial(dev, baudrate=115200, timeout=5)
uartp = UARTP(ser)
flash()
eprint("Flashed")
time.sleep(0.1)
ser.setDTR(False) # IO0=HIGH
ser.setRTS(True) # EN=LOW, chip in reset
time.sleep(0.1)
ser.setDTR(False) # IO0=HIGH
ser.setRTS(False) # EN=HIGH, chip out of reset
time.sleep(1)
def stdin_read(n):
b = sys.stdin.buffer.read(n)
if len(b) != n:
sys.exit(1)
return b
def stdin_readvar():
l = stdin_read(4)
(l, ) = struct.unpack("<I", l)
v = stdin_read(l)
return v
exp_hello = b"Hello, World!"
hello = ser.read(ser.in_waiting)
if hello[-13:] != exp_hello:
eprint("Improper board initialization message: %s" % hello)
return 1
eprint("Board initialized properly")
sys.stdout.write("Hello, World!\n")
sys.stdout.flush()
while 1:
action = stdin_read(1)[0]
eprint("Command %c from stdin" % action)
if action in b"ackmps":
v = stdin_readvar()
uartp.send(struct.pack("B", action) + v)
ack = uartp.recv()
if len(ack) != 1 or ack[0] != action:
raise Exception("Unacknowledged variable transfer")
eprint("Var %c successfully sent to board" % action)
elif action in b"ACKMPS":
c = struct.pack("B", action)
uartp.send(c)
v = uartp.recv()
if len(v) < 1 or v[0] != action:
raise Exception("Could not obtain variable from board")
v = v[1:]
eprint("Var %c received from board: %s" % (action, v.hex()))
l = struct.pack("<I", len(v))
sys.stdout.buffer.write(l + v)
sys.stdout.flush()
elif action in b"ed":
c = struct.pack("B", action)
uartp.send(c)
ack = uartp.recv()
if len(ack) != 1 or ack[0] != action:
raise Exception("Unacknowledged variable transfer")
eprint("Operation %c completed successfully" % action)
else:
raise Exception("Unknown action %c" % action)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment