Skip to content
Snippets Groups Projects
Commit 877a9e8f authored by Christos Gentsos's avatar Christos Gentsos
Browse files

General: split the different programs to different directories (1/2)

The four different programs being:
- the main FW
- the bootloader
- the test I2C master
- the secondary test program used to test I2C programming
parent 70c85a45
Branches
Tags
No related merge requests found
......@@ -103,22 +103,7 @@ SECTIONS
_etext = LOADADDR(.text) + SIZEOF(.text);
.text_mbl :
{
. = ALIGN(4);
_smockbl = .;
KEEP (*mock_bl*)
. = ALIGN(4);
_emockbl = .;
} > bootloader
.user_flash :
{
. = ALIGN(4);
user_flash = .;
LONG(0xBEC0ABCD)
. = ALIGN(4);
} > user_flash
user_flash = ORIGIN(user_flash);
.relocate : AT (_etext)
{
......
/**
* \file
*
* \brief Linker script for running in internal FLASH on the SAMD21G18A
*
* Copyright (c) 2018 Microchip Technology Inc.
*
* \asf_license_start
*
* \page License
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the Licence at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* \asf_license_stop
*
*/
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
SEARCH_DIR(.)
/* Memory Spaces Definitions */
MEMORY
{
bootloader (rx) : ORIGIN = 0x00000000, LENGTH = 0x00001f00
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
}
/* The stack size used by the application. NOTE: you need to adjust according to your application. */
STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : DEFINED(__stack_size__) ? __stack_size__ : 0x2000;
/* Section Definitions */
SECTIONS
{
.text :
{
. = ALIGN(4);
_sfixed = .;
KEEP(*(.vectors .vectors.*))
*(.text .text.* .gnu.linkonce.t.*)
*(.glue_7t) *(.glue_7)
*(.rodata .rodata* .gnu.linkonce.r.*)
*(.ARM.extab* .gnu.linkonce.armextab.*)
/* Support C constructors, and C destructors in both user code
and the C library. This also provides support for C++ code. */
. = ALIGN(4);
KEEP(*(.init))
. = ALIGN(4);
__preinit_array_start = .;
KEEP (*(.preinit_array))
__preinit_array_end = .;
. = ALIGN(4);
__init_array_start = .;
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
__init_array_end = .;
. = ALIGN(4);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*crtend.o(.ctors))
. = ALIGN(4);
KEEP(*(.fini))
. = ALIGN(4);
__fini_array_start = .;
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
__fini_array_end = .;
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*crtend.o(.dtors))
. = ALIGN(4);
_efixed = .; /* End of text section */
} > bootloader
. = ALIGN(4);
_etext = .;
user_flash = LENGTH(bootloader);
.relocate : AT (_etext)
{
. = ALIGN(4);
_srelocate = .;
*(.ramfunc .ramfunc.*);
*(.data .data.*);
. = ALIGN(4);
_erelocate = .;
} > ram
/* .bss section which is used for uninitialized data */
.bss (NOLOAD) :
{
. = ALIGN(4);
_sbss = . ;
_szero = .;
*(.bss .bss.*)
*(COMMON)
. = ALIGN(4);
_ebss = . ;
_ezero = .;
} > ram
/* stack section */
.stack (NOLOAD):
{
. = ALIGN(8);
_sstack = .;
. = . + STACK_SIZE;
. = ALIGN(8);
_estack = .;
} > ram
. = ALIGN(4);
_end = . ;
}
......@@ -120,25 +120,13 @@ all: $(SUB_DIRS) $(OUTPUT_FILE_PATH)
# Linker target
$(OUTPUT_FILE_PATH): $(OBJS) ../src/main.o ../src/main_mockbl.o
$(OUTPUT_FILE_PATH): $(OBJS) ../src/main.o
# to disable floats in printf (which take up *a lot* of space) remove -lc -u _printf_float
@echo Building mock bootloader
@echo Invoking: ARM/GNU Linker
$(QUOTE)arm-none-eabi-gcc$(QUOTE) -o mock_bl.elf $(OBJS_AS_ARGS) "../src/main_mockbl.o" -Wl,--start-group -lm -Wl,--end-group -mthumb \
-Wl,-Map="$(OUTPUT_FILE_NAME)_mockbl.map" --specs=nano.specs -Wl,--gc-sections -mcpu=cortex-m0plus \
\
-T"../atmel_start_prj/samd21a/gcc/gcc/samd21g18a_flash_mockbl.ld" \
-L"../atmel_start_prj/samd21a/gcc/gcc"
"arm-none-eabi-objcopy" -O binary "mock_bl.elf" "mock_bl.bin"
"arm-none-eabi-objcopy" -I binary -O elf32-littlearm -B armv6s-m mock_bl.bin mock_bl_out.elf
"arm-none-eabi-objdump" -h -S "mock_bl.elf" > "mock_bl.lss"
@echo Finished building mock bootloader
@echo Building target: $@
@echo Invoking: ARM/GNU Linker
$(QUOTE)arm-none-eabi-gcc$(QUOTE) -o $(OUTPUT_FILE_NAME).elf $(OBJS_AS_ARGS) "../src/main.o" mock_bl_out.elf -Wl,--start-group -lm -lc -u _printf_float -Wl,--end-group -mthumb \
$(QUOTE)arm-none-eabi-gcc$(QUOTE) -o $(OUTPUT_FILE_NAME).elf $(OBJS_AS_ARGS) ../src/main.o -Wl,--start-group -lm -lc -u _printf_float -Wl,--end-group -mthumb \
-Wl,-Map="$(OUTPUT_FILE_NAME).map" --specs=nano.specs -Wl,--gc-sections -mcpu=cortex-m0plus \
\
-T"../atmel_start_prj/samd21a/gcc/gcc/samd21g18a_flash.ld" \
......
h
loadbin AtmelStart.bin 0x0000
loadbin user_flash.bin 0x1f00
loadbin AtmelStart.bin 0x22000
r
g
qc
File added
......@@ -95,16 +95,7 @@ SECTIONS
_efixed = .; /* End of text section */
} > rom
_smodfw = LOADADDR(.text_mfw);
_emodfw = LOADADDR(.text_mfw) + SIZEOF(.text_mfw);
.text_mfw 0x2000:
{
. = ALIGN(4);
KEEP (mod_fw*)
. = ALIGN(4);
} AT > rom_mfw
_etext = _emodfw;
_etext = .;
.relocate : AT (_etext)
{
......
/**
* \file
*
* \brief Linker script for running in internal FLASH on the SAMD21G18A
*
* Copyright (c) 2018 Microchip Technology Inc.
*
* \asf_license_start
*
* \page License
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the Licence at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* \asf_license_stop
*
*/
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
SEARCH_DIR(.)
/* Memory Spaces Definitions */
MEMORY
{
rom (rx) : ORIGIN = 0x00002000, LENGTH = 0x0001e000
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
}
/* The stack size used by the application. NOTE: you need to adjust according to your application. */
STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : DEFINED(__stack_size__) ? __stack_size__ : 0x2000;
/* Section Definitions */
SECTIONS
{
.text :
{
. = ALIGN(4);
_sfixed = .;
KEEP(*(.vectors .vectors.*))
*(.text .text.* .gnu.linkonce.t.*)
*(.glue_7t) *(.glue_7)
*(.rodata .rodata* .gnu.linkonce.r.*)
*(.ARM.extab* .gnu.linkonce.armextab.*)
/* Support C constructors, and C destructors in both user code
and the C library. This also provides support for C++ code. */
. = ALIGN(4);
KEEP(*(.init))
. = ALIGN(4);
__preinit_array_start = .;
KEEP (*(.preinit_array))
__preinit_array_end = .;
. = ALIGN(4);
__init_array_start = .;
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
__init_array_end = .;
. = ALIGN(4);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*crtend.o(.ctors))
. = ALIGN(4);
KEEP(*(.fini))
. = ALIGN(4);
__fini_array_start = .;
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
__fini_array_end = .;
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*crtend.o(.dtors))
. = ALIGN(4);
_efixed = .; /* End of text section */
} > rom
. = ALIGN(4);
_etext = .;
.relocate : AT (_etext)
{
. = ALIGN(4);
_srelocate = .;
*(.ramfunc .ramfunc.*);
*(.data .data.*);
. = ALIGN(4);
_erelocate = .;
} > ram
/* .bss section which is used for uninitialized data */
.bss (NOLOAD) :
{
. = ALIGN(4);
_sbss = . ;
_szero = .;
*(.bss .bss.*)
*(COMMON)
. = ALIGN(4);
_ebss = . ;
_ezero = .;
} > ram
/* stack section */
.stack (NOLOAD):
{
. = ALIGN(8);
_sstack = .;
. = . + STACK_SIZE;
. = ALIGN(8);
_estack = .;
} > ram
. = ALIGN(4);
_end = . ;
}
......@@ -63,7 +63,8 @@ hpl/dmac/hpl_dmac.o \
atmel_start.o \
usb/device/usbdc.o \
hal/src/hal_atomic.o \
hpl/adc/hpl_adc.o
hpl/adc/hpl_adc.o \
../../common/src/checksums.o
OBJS_AS_ARGS += $(OBJS:%="%")
......@@ -114,25 +115,13 @@ all: $(SUB_DIRS) $(OUTPUT_FILE_PATH)
# Linker target
$(OUTPUT_FILE_PATH): $(OBJS) ../src/main.o ../src/main_secondary.o
$(OUTPUT_FILE_PATH): $(OBJS) ../src/main.o
# to disable floats in printf (which take up *a lot* of space) remove -lc -u _printf_float
@echo Building secondary program file
@echo Invoking: ARM/GNU Linker
$(QUOTE)arm-none-eabi-gcc$(QUOTE) -o mod_fw.elf $(OBJS_AS_ARGS) "../src/main_secondary.o" -Wl,--start-group -lm -lc -u _printf_float -Wl,--end-group -mthumb \
-Wl,-Map="$(OUTPUT_FILE_NAME)_secondary.map" --specs=nano.specs -Wl,--gc-sections -mcpu=cortex-m0plus \
\
-T"../atmel_start_prj/samd21a/gcc/gcc/samd21g18a_flash_secondary.ld" \
-L"../atmel_start_prj/samd21a/gcc/gcc"
"arm-none-eabi-objcopy" -O binary "mod_fw.elf" "mod_fw.bin"
"arm-none-eabi-objcopy" -I binary -O elf32-littlearm -B armv6s-m mod_fw.bin mod_fw_out.elf
"arm-none-eabi-objdump" -h -S "mod_fw.elf" > "mod_fw.lss"
@echo Finished building secondary program file
@echo Building target: $@
@echo Invoking: ARM/GNU Linker
$(QUOTE)arm-none-eabi-gcc$(QUOTE) -o $(OUTPUT_FILE_NAME).elf $(OBJS_AS_ARGS) "../src/main.o" mod_fw_out.elf -Wl,--start-group -lm -lc -u _printf_float -Wl,--end-group -mthumb \
$(QUOTE)arm-none-eabi-gcc$(QUOTE) -o $(OUTPUT_FILE_NAME).elf $(OBJS_AS_ARGS) ../src/main.o -Wl,--start-group -lm -lc -u _printf_float -Wl,--end-group -mthumb \
-Wl,-Map="$(OUTPUT_FILE_NAME).map" --specs=nano.specs -Wl,--gc-sections -mcpu=cortex-m0plus \
\
-T"../atmel_start_prj/samd21a/gcc/gcc/samd21g18a_flash.ld" \
......
#include <atmel_start.h>
#include <stdlib.h>
#include "usb_debug.h"
#include <usb_debug.h>
#include <checksums.h>
extern uint32_t _smodfw;
extern uint32_t _emodfw;
int comp_sysv_checksum()
{
uint32_t result = 0;
uint16_t result16 = 0;
uint8_t *p = (uint8_t *)&_smodfw;
while (p != (uint8_t *)&_emodfw)
result += *(p++);
result16 = (result & 0xffff) + ((result & 0xffffffff) >> 16);
return (result16 & 0xffff) + (result16 >> 16);
}
#define MOD_FW_START 0x22000
#define MOD_FW_LENGTH 0x1e000
void debug_print_array(uint8_t *p, uint8_t len)
{
......@@ -128,18 +118,16 @@ int main(void)
struct io_descriptor *I2C_0_io;
uint16_t checksum;
checksum = comp_sysv_checksum();
checksum = sysv_checksum((uint8_t *)MOD_FW_START, (uint8_t *)(MOD_FW_START + MOD_FW_LENGTH));
i2c_m_sync_get_io_descriptor(&I2C_0, &I2C_0_io);
i2c_m_sync_enable(&I2C_0);
i2c_m_sync_set_slaveaddr(&I2C_0, 0x12, I2C_M_SEVEN);
uint32_t fw_size = (uint32_t)&_emodfw - (uint32_t)&_smodfw;
uint8_t zero8[8];
memset(zero8, 0, 8);
uint8_t *send_p = (uint8_t *)&_smodfw;
uint8_t *send_p;
uint16_t myblock = 0;
int i = 0;
......@@ -154,23 +142,23 @@ int main(void)
gpio_toggle_pin_level(LED);
switch (usb_read_buf) {
case 'f':
debug("s = %ld, e = %ld, fw_size = %ld (%ld blocks), fw_remainder = %ld", (uint32_t)&_smodfw, (uint32_t)&_emodfw, fw_size, fw_size / 8, fw_size % 8);
uint16_t n_blocks = fw_size / 8;
debug("s = %ld, fw_size = %ld (%ld blocks), fw_remainder = %ld", (uint32_t)MOD_FW_START, (uint32_t)MOD_FW_LENGTH, (uint32_t)MOD_FW_LENGTH / 8, (uint32_t)MOD_FW_LENGTH % 8);
uint16_t n_blocks = MOD_FW_LENGTH / 8;
/* first write size in 16-byte blocks */
i2c_m_sync_ext_cmd_write(&I2C_0, 0x1, (uint8_t *)&n_blocks, 2);
send_p = (uint8_t *)&_smodfw;
send_p = (uint8_t *)MOD_FW_START;
myblock = 0;
while ((send_p + 7) < (uint8_t *)&_emodfw) {
while ((send_p + 7) < (uint8_t *)(MOD_FW_START + MOD_FW_LENGTH)) {
i2c_m_sync_ext_cmd_write(&I2C_0, 0x2, send_p, 8);
send_p += 8;
debug("written %d, a = %d", ++myblock, (int)send_p);
/* delay_ms(1); */
}
if (fw_size % 8) {
i2c_m_sync_ext_cmd_write(&I2C_0, 0x2, send_p, fw_size % 8);
i2c_m_sync_ext_cmd_write(&I2C_0, 0x2, zero8, 8 - (fw_size % 8));
if (MOD_FW_LENGTH % 8) {
i2c_m_sync_ext_cmd_write(&I2C_0, 0x2, send_p, MOD_FW_LENGTH % 8);
i2c_m_sync_ext_cmd_write(&I2C_0, 0x2, zero8, 8 - (MOD_FW_LENGTH % 8));
}
i2c_m_sync_ext_cmd_write(&I2C_0, 0x3, (uint8_t *)&checksum, 2);
break;
......
#include <atmel_start.h>
#include "usb_debug.h"
int main(void)
{
/* Initializes MCU, drivers and middleware */
atmel_start_init();
int i = 0;
adc_sync_enable_channel(&ADC_0, 0);
uint16_t adc_val;
float adc_temp;
/* Replace with your application code */
while (1) {
delay_ms(500);
gpio_toggle_pin_level(LED);
if (i++ % 2) {
adc_sync_read_channel(&ADC_0, 0, (uint8_t*)&adc_val, 2);
adc_temp = ((adc_val / 4095.0) - 0.6)/0.01;
debug("secondary FW from i2c master: iter %d, temp=%.1f", i/2, adc_temp);
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment