aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'pyecsca/codegen')
-rw-r--r--pyecsca/codegen/common.py1
-rw-r--r--pyecsca/codegen/hal/Makefile.hal7
-rw-r--r--pyecsca/codegen/hal/hal.h7
-rw-r--r--pyecsca/codegen/hal/stm32f0_nano/LinkerScript.ld202
-rw-r--r--pyecsca/codegen/hal/stm32f0_nano/Makefile.stm32f0_nano28
-rw-r--r--pyecsca/codegen/hal/stm32f0_nano/stm32f0_hal_nano.c136
6 files changed, 378 insertions, 3 deletions
diff --git a/pyecsca/codegen/common.py b/pyecsca/codegen/common.py
index 917963e..d180780 100644
--- a/pyecsca/codegen/common.py
+++ b/pyecsca/codegen/common.py
@@ -19,6 +19,7 @@ class Platform(EnumDefine):
XMEGA = "CW308_XMEGA"
STM32F0 = "CW308_STM32F0"
STM32F3 = "CW308_STM32F3"
+ NANO = "CWNANO"
@public
diff --git a/pyecsca/codegen/hal/Makefile.hal b/pyecsca/codegen/hal/Makefile.hal
index 186b96e..cb0e848 100644
--- a/pyecsca/codegen/hal/Makefile.hal
+++ b/pyecsca/codegen/hal/Makefile.hal
@@ -9,13 +9,15 @@ VPATH += :$(HALPATH)
#Default stuff
EXTRAINCDIRS += $(HALPATH)
-PLATFORM_LIST = CW308_STM32F0 CW308_STM32F3 CW308_XMEGA HOST
+PLATFORM_LIST = CW308_STM32F0 CW308_STM32F3 CW308_XMEGA CWNANO HOST
define KNOWN_PLATFORMS
+-------------------------------------------------------+
| CW308_XMEGA | CW308T-XMEGA |
+-------------------------------------------------------+
+| CWNANO | CW-Lite Nano (STM32F0_NANO) |
++-------------------------------------------------------+
| CW308_STM32F0 | CW308T-STM32F0 (ST Micro STM32F0) |
+-------------------------------------------------------+
| CW308_STM32F3 | CW308T-STM32F3 (ST Micro STM32F3) |
@@ -37,6 +39,9 @@ ifeq ($(PLATFORM),CW308_XMEGA)
MCU = atxmega128d3
HAL = xmega
PLTNAME = CW308T: XMEGA Target
+else ifeq ($(PLATFORM),CWNANO)
+ HAL = stm32f0_nano
+ PLTNAME = CWNANO Built-in Target (STM32F030)
else ifeq ($(PLATFORM),CW308_STM32F0)
HAL = stm32f0
PLTNAME = CW308T: STM32F0 Target
diff --git a/pyecsca/codegen/hal/hal.h b/pyecsca/codegen/hal/hal.h
index 038415d..181113a 100644
--- a/pyecsca/codegen/hal/hal.h
+++ b/pyecsca/codegen/hal/hal.h
@@ -23,8 +23,9 @@ void platform_init(void);
#define HAL_xmega 1
#define HAL_stm32f0 2
-#define HAL_stm32f3 3
-#define HAL_host 4
+#define HAL_stm32f0_nano 3
+#define HAL_stm32f3 4
+#define HAL_host 5
#if HAL == HAL_xmega
#include <avr/io.h>
@@ -33,6 +34,8 @@ void platform_init(void);
#include "xmega/avr_compiler.h"
#elif HAL == HAL_stm32f0
#include "stm32f0/stm32f0_hal.h"
+#elif HAL == HAL_stm32f0_nano
+ #include "stm32f0/stm32f0_hal.h"
#elif HAL == HAL_stm32f3
#include "stm32f3/stm32f3_hal.h"
#elif HAL == HAL_host
diff --git a/pyecsca/codegen/hal/stm32f0_nano/LinkerScript.ld b/pyecsca/codegen/hal/stm32f0_nano/LinkerScript.ld
new file mode 100644
index 0000000..b1b4c5b
--- /dev/null
+++ b/pyecsca/codegen/hal/stm32f0_nano/LinkerScript.ld
@@ -0,0 +1,202 @@
+/*
+******************************************************************************
+**
+** File : LinkerScript.ld
+**
+** Author : Auto-generated by Ac6 System Workbench
+**
+** Abstract : Linker script for STM32F030F4Px Device from STM32F0 series
+** 4Kbytes RAM
+** 16Kbytes ROM
+**
+** Set heap size, stack size and stack location according
+** to application requirements.
+**
+** Set memory bank area and size if external memory is used.
+**
+** Target : STMicroelectronics STM32
+**
+** Distribution: The file is distributed “as is,” without any warranty
+** of any kind.
+**
+*****************************************************************************
+** @attention
+**
+** <h2><center>&copy; COPYRIGHT(c) 2018 Ac6</center></h2>
+**
+** Redistribution and use in source and binary forms, with or without modification,
+** are permitted provided that the following conditions are met:
+** 1. Redistributions of source code must retain the above copyright notice,
+** this list of conditions and the following disclaimer.
+** 2. Redistributions in binary form must reproduce the above copyright notice,
+** this list of conditions and the following disclaimer in the documentation
+** and/or other materials provided with the distribution.
+** 3. Neither the name of Ac6 nor the names of its contributors
+** may be used to endorse or promote products derived from this software
+** without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+**
+*****************************************************************************
+*/
+
+/* Entry Point */
+ENTRY(Reset_Handler)
+
+/* Highest address of the user mode stack */
+_estack = 0x20001000; /* end of RAM */
+
+_Min_Heap_Size = 0; /* required amount of heap */
+_Min_Stack_Size = 0x400; /* required amount of stack */
+
+/* Memories definition */
+MEMORY
+{
+ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 4K
+ ROM (rx) : ORIGIN = 0x8000000, LENGTH = 16K
+}
+
+/* Sections */
+SECTIONS
+{
+ /* The startup code into ROM memory */
+ .isr_vector :
+ {
+ . = ALIGN(4);
+ KEEP(*(.isr_vector)) /* Startup code */
+ . = ALIGN(4);
+ } >ROM
+
+ /* The program code and other data into ROM memory */
+ .text :
+ {
+ . = ALIGN(4);
+ *(.text) /* .text sections (code) */
+ *(.text*) /* .text* sections (code) */
+ *(.glue_7) /* glue arm to thumb code */
+ *(.glue_7t) /* glue thumb to arm code */
+ *(.eh_frame)
+
+ KEEP (*(.init))
+ KEEP (*(.fini))
+
+ . = ALIGN(4);
+ _etext = .; /* define a global symbols at end of code */
+ } >ROM
+
+ /* Constant data into ROM memory*/
+ .rodata :
+ {
+ . = ALIGN(4);
+ *(.rodata) /* .rodata sections (constants, strings, etc.) */
+ *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
+ . = ALIGN(4);
+ } >ROM
+
+ .ARM.extab : {
+ . = ALIGN(4);
+ *(.ARM.extab* .gnu.linkonce.armextab.*)
+ . = ALIGN(4);
+ } >ROM
+
+ .ARM : {
+ . = ALIGN(4);
+ __exidx_start = .;
+ *(.ARM.exidx*)
+ __exidx_end = .;
+ . = ALIGN(4);
+ } >ROM
+
+ .preinit_array :
+ {
+ . = ALIGN(4);
+ PROVIDE_HIDDEN (__preinit_array_start = .);
+ KEEP (*(.preinit_array*))
+ PROVIDE_HIDDEN (__preinit_array_end = .);
+ . = ALIGN(4);
+ } >ROM
+
+ .init_array :
+ {
+ . = ALIGN(4);
+ PROVIDE_HIDDEN (__init_array_start = .);
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array*))
+ PROVIDE_HIDDEN (__init_array_end = .);
+ . = ALIGN(4);
+ } >ROM
+
+ .fini_array :
+ {
+ . = ALIGN(4);
+ PROVIDE_HIDDEN (__fini_array_start = .);
+ KEEP (*(SORT(.fini_array.*)))
+ KEEP (*(.fini_array*))
+ PROVIDE_HIDDEN (__fini_array_end = .);
+ . = ALIGN(4);
+ } >ROM
+
+ /* Used by the startup to initialize data */
+ _sidata = LOADADDR(.data);
+
+ /* Initialized data sections into RAM memory */
+ .data :
+ {
+ . = ALIGN(4);
+ _sdata = .; /* create a global symbol at data start */
+ *(.data) /* .data sections */
+ *(.data*) /* .data* sections */
+
+ . = ALIGN(4);
+ _edata = .; /* define a global symbol at data end */
+ } >RAM AT> ROM
+
+
+ /* Uninitialized data section into RAM memory */
+ . = ALIGN(4);
+ .bss :
+ {
+ /* This is used by the startup in order to initialize the .bss secion */
+ _sbss = .; /* define a global symbol at bss start */
+ __bss_start__ = _sbss;
+ *(.bss)
+ *(.bss*)
+ *(COMMON)
+
+ . = ALIGN(4);
+ _ebss = .; /* define a global symbol at bss end */
+ __bss_end__ = _ebss;
+ } >RAM
+
+ /* User_heap_stack section, used to check that there is enough RAM left */
+ ._user_heap_stack :
+ {
+ . = ALIGN(8);
+ PROVIDE ( end = . );
+ PROVIDE ( _end = . );
+ . = . + _Min_Heap_Size;
+ . = . + _Min_Stack_Size;
+ . = ALIGN(8);
+ } >RAM
+
+
+
+ /* Remove information from the compiler libraries */
+ /DISCARD/ :
+ {
+ libc.a ( * )
+ libm.a ( * )
+ libgcc.a ( * )
+ }
+
+ .ARM.attributes 0 : { *(.ARM.attributes) }
+}
diff --git a/pyecsca/codegen/hal/stm32f0_nano/Makefile.stm32f0_nano b/pyecsca/codegen/hal/stm32f0_nano/Makefile.stm32f0_nano
new file mode 100644
index 0000000..b7782c1
--- /dev/null
+++ b/pyecsca/codegen/hal/stm32f0_nano/Makefile.stm32f0_nano
@@ -0,0 +1,28 @@
+VPATH += :$(HALPATH)/stm32f0
+VPATH += :$(HALPATH)/stm32f0_nano
+SRC += stm32f0_hal_nano.c stm32f0_hal_lowlevel.c
+EXTRAINCDIRS += $(HALPATH)/stm32f0 $(HALPATH)/stm32f0/CMSIS $(HALPATH)/stm32f0/CMSIS/core $(HALPATH)/stm32f0/CMSIS/device $(HALPATH)/stm32f0/Legacy
+
+ASRC += stm32f0_startup.S
+
+MCU_FLAGS = -mcpu=cortex-m0
+
+CC = arm-none-eabi-gcc
+OBJCOPY = arm-none-eabi-objcopy
+OBJDUMP = arm-none-eabi-objdump
+SIZE = arm-none-eabi-size
+AR = arm-none-eabi-ar rcs
+NM = arm-none-eabi-nm
+
+#Output Format = Binary for this target
+FORMAT = binary
+
+CFLAGS += -mthumb -mfloat-abi=soft -ffunction-sections
+CPPFLAGS += -mthumb -mfloat-abi=soft -ffunction-sections
+ASFLAGS += -mthumb -mfloat-abi=soft -ffunction-sections
+
+CDEFS += -DSTM32F030x6 -DSTM32F0 -DSTM32 -DDEBUG
+CPPDEFS += -DSTM32F030x6 -DSTM32F0 -DSTM32 -DDEBUG
+
+LDFLAGS += --specs=nano.specs --specs=nosys.specs -T $(HALPATH)/stm32f0_nano/LinkerScript.ld -Wl,--gc-sections -lm
+LDFLAGS += -mthumb -mcpu=cortex-m0 \ No newline at end of file
diff --git a/pyecsca/codegen/hal/stm32f0_nano/stm32f0_hal_nano.c b/pyecsca/codegen/hal/stm32f0_nano/stm32f0_hal_nano.c
new file mode 100644
index 0000000..d6fdb3c
--- /dev/null
+++ b/pyecsca/codegen/hal/stm32f0_nano/stm32f0_hal_nano.c
@@ -0,0 +1,136 @@
+
+#include "stm32f0_hal.h"
+#include "stm32f0_hal_lowlevel.h"
+#include "stm32f0xx_hal_rcc.h"
+#include "stm32f0xx_hal_gpio.h"
+#include "stm32f0xx_hal_dma.h"
+#include "stm32f0xx_hal_uart.h"
+#include "stm32f0xx_hal_flash.h"
+
+UART_HandleTypeDef UartHandle;
+
+
+void platform_init(void)
+{
+ /* LEDs */
+ GPIO_InitTypeDef GpioInit;
+ GpioInit.Pin = GPIO_PIN_2;
+ GpioInit.Mode = GPIO_MODE_OUTPUT_PP;
+ GpioInit.Pull = GPIO_NOPULL;
+ GpioInit.Speed = GPIO_SPEED_FREQ_HIGH;
+ HAL_GPIO_Init(GPIOA, &GpioInit);
+
+ GpioInit.Pin = GPIO_PIN_4;
+ GpioInit.Mode = GPIO_MODE_OUTPUT_PP;
+ GpioInit.Pull = GPIO_NOPULL;
+ GpioInit.Speed = GPIO_SPEED_FREQ_HIGH;
+ HAL_GPIO_Init(GPIOA, &GpioInit);
+
+#ifdef USE_INTERNAL_CLK
+ RCC_OscInitTypeDef RCC_OscInitStruct;
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
+ RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
+ RCC_OscInitStruct.HSIState = RCC_HSI_ON;
+ RCC_OscInitStruct.PLL.PLLSource = RCC_PLL_NONE;
+ HAL_RCC_OscConfig(&RCC_OscInitStruct);
+
+ RCC_ClkInitTypeDef RCC_ClkInitStruct;
+ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
+ RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
+ RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
+ RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
+ uint32_t flash_latency = 0;
+ HAL_RCC_ClockConfig(&RCC_ClkInitStruct, flash_latency);
+#else
+ RCC_OscInitTypeDef RCC_OscInitStruct;
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI;
+ RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
+ RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
+ RCC_OscInitStruct.PLL.PLLSource = RCC_PLL_NONE;
+ HAL_RCC_OscConfig(&RCC_OscInitStruct);
+
+ RCC_ClkInitTypeDef RCC_ClkInitStruct;
+ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1);
+ RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;
+ RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
+ HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
+#endif
+}
+
+void init_uart(void)
+{
+ __HAL_RCC_GPIOA_CLK_ENABLE();
+ GPIO_InitTypeDef GpioInit;
+ GpioInit.Pin = GPIO_PIN_9 | GPIO_PIN_10;
+ GpioInit.Mode = GPIO_MODE_AF_PP;
+ GpioInit.Pull = GPIO_PULLUP;
+ GpioInit.Speed = GPIO_SPEED_FREQ_HIGH;
+ GpioInit.Alternate = GPIO_AF1_USART1;
+ HAL_GPIO_Init(GPIOA, &GpioInit);
+
+ __HAL_RCC_USART1_CLK_ENABLE();
+ __HAL_RCC_USART1_CONFIG(RCC_USART1CLKSOURCE_SYSCLK);
+ UartHandle.Instance = USART1;
+ #if SS_VER==SS_VER_2_0
+ UartHandle.Init.BaudRate = 230400;
+ #else
+ UartHandle.Init.BaudRate = 38400;
+ #endif
+ UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
+ UartHandle.Init.StopBits = UART_STOPBITS_1;
+ UartHandle.Init.Parity = UART_PARITY_NONE;
+ UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+ UartHandle.Init.Mode = UART_MODE_TX_RX;
+ HAL_UART_Init(&UartHandle);
+}
+
+void trigger_setup(void)
+{
+ __HAL_RCC_GPIOA_CLK_ENABLE();
+
+ GPIO_InitTypeDef GpioInit;
+ GpioInit.Pin = GPIO_PIN_7;
+ GpioInit.Mode = GPIO_MODE_OUTPUT_PP;
+ GpioInit.Pull = GPIO_NOPULL;
+ GpioInit.Speed = GPIO_SPEED_FREQ_HIGH;
+ HAL_GPIO_Init(GPIOA, &GpioInit);
+
+ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, RESET);
+}
+
+void trigger_high(void)
+{
+ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, SET);
+}
+
+void trigger_low(void)
+{
+ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, RESET);
+}
+
+char getch(void)
+{
+ uint8_t d;
+ while(HAL_UART_Receive(&UartHandle, &d, 1, 50) != HAL_OK)
+ USART1->ICR |= (1 << 3); // make sure overrun error is cleared, otherwise can stall here
+ return d;
+}
+
+void putch(char c)
+{
+ uint8_t d = c;
+ HAL_UART_Transmit(&UartHandle, &d, 1, 5000);
+}
+
+
+void led_error(unsigned int status)
+{
+ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, status);
+}
+
+void led_ok(unsigned int status)
+{
+ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, status);
+}