Commit ec01da59 by Sebastian Renner

Debugging blackpill

parent 1a96b767
Read following action from stdin: c
Data sent to serial: b'c \x00\x00\x00'
Data sent to serial: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Read following action from stdin: s
Data sent to serial: b's\x00\x00\x00\x00'
Data sent to serial: b''
Read following action from stdin: m
Data sent to serial: b'm\x00\x00\x00\x00'
Data sent to serial: b''
Read following action from stdin: a
Data sent to serial: b'a\x00\x00\x00\x00'
Data sent to serial: b''
Read following action from stdin: k
Data sent to serial: b'k\x10\x00\x00\x00'
Data sent to serial: b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
Read following action from stdin: p
Data sent to serial: b'p\x0f\x00\x00\x00'
Data sent to serial: b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e'
Read following action from stdin: e
Data sent to serial: b'e'
Read following action from stdin: C
Data sent to serial: b'C'
......@@ -46,6 +46,8 @@ Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_gpio.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_pwr.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usart.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_dma.c \
Src/RTT/SEGGER_RTT.c \
Src/RTT/SEGGER_RTT_printf.c \
$(SRC_FILES)
# ASM sources
......
......@@ -43,8 +43,11 @@
#include <stdint.h>
#include "crypto_aead.h"
#include "api.h"
#include "SEGGER_RTT.h"
#include "SEGGER_RTT_Conf.h"
#define MAX_LEN 1400
#define dbg_printf(...) SEGGER_RTT_printf(0, __VA_ARGS__)
unsigned char c[MAX_LEN];
unsigned long long clen = 0;
......@@ -52,7 +55,7 @@ unsigned char m[MAX_LEN];
unsigned long long mlen = 0;
unsigned char ad[MAX_LEN];
unsigned long long adlen = 0;
unsigned char text[6] = "HELLO";
unsigned char text[2] = "OK";
unsigned char nsec[CRYPTO_NSECBYTES];
const unsigned long long nslen = CRYPTO_NSECBYTES;
......@@ -79,7 +82,7 @@ static void read_serial(void *dst, unsigned int len) {
static void write_serial(const void *src, unsigned int len) {
const unsigned char *buf = src;
for (int i = 0; i < len; i++) {
while (!LL_USART_IsActiveFlag_TXE(USART1));
while (!(LL_USART_IsActiveFlag_TXE(USART1)));
LL_USART_TransmitData8(USART1, buf[i]);
}
}
......@@ -156,7 +159,7 @@ int main(void)
SystemClock_Config();
/* USER CODE BEGIN SysInit */
SEGGER_RTT_Init();
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
......@@ -173,6 +176,7 @@ int main(void)
while (1) {
read_serial(&rcv, sizeof(rcv));
dbg_printf("Received char: %c\n", rcv);
switch (rcv) {
case 'c':
case 'm':
......@@ -183,16 +187,7 @@ int main(void)
read_variable_serial(rcv);
break;
case 'C':
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
write_variable_serial(c, clen);
break;
case 'C': write_variable_serial(c, clen); break;
case 'M': write_variable_serial(m, mlen); break;
case 'A': write_variable_serial(ad, adlen); break;
case 'K': write_variable_serial(k, klen); break;
......@@ -200,29 +195,15 @@ int main(void)
case 'P': write_variable_serial(npub, nplen); break;
case 'd':
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
res = crypto_aead_decrypt(m, &mlen, nsec, c, clen, ad, adlen, npub, k);
break;
case 'e':
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
LL_mDelay(500);
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_12);
res = crypto_aead_encrypt(c, &clen, m, mlen, ad, adlen, nsec, npub, k);
break;
default:
LL_mDelay(1);
LL_mDelay(500);
}
/* USER CODE END WHILE */
......
......@@ -4,4 +4,3 @@ device STM32F103C8
loadbin build/blackpill.bin 0x8000000
r
g
exit
......@@ -38,6 +38,7 @@ def write(channel, data):
def obtain(channel):
l = read(channel, 4)
l = str.encode(l)
f.write("Trying to read " + str(l) + "bytes from " + channel + "\n")
(l, ) = struct.unpack("<I", l)
return read(channel, l)
......
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