From e321b909729228328bcbaa35d6313996a7114983 Mon Sep 17 00:00:00 2001 From: Josepablo C Date: Sun, 3 Nov 2024 02:45:13 -0600 Subject: [PATCH] feat(TM4C123 and Windows): Adding support for GCC on windows Adding support for TM4C123 and VSCode Cortex Debug with OpenOCD and ARM GDB Changes to linker script and startup code were needed. Disabling Middlewares was also required, just keeping TivaWare Drivers in place for making the current code compatible with TM4C123. This is a quick and dirty solution, improvements are required. --- .vscode/.cortex-debug.registers.state.json | 1 - .vscode/c_cpp_properties.json | 20 ++ .vscode/launch.json | 7 +- .vscode/settings.json | 6 + project/BSP/CMakeLists.txt | 3 +- project/BSP/src/Board.c | 32 ++- ...artup_gcc.c => startup_gcc_tm4c123gh6pm.c} | 4 +- project/BSP/src/startup_gcc_tm4c1294ncpdt.c | 238 ++++++++++++++++++ project/CMakeLists.txt | 2 + project/Tasks/CMakeLists.txt | 7 - project/Tasks/src/Tasks.c | 28 +-- project/cmake/TM4C123GH6PM_cfg.ld | 40 +++ .../{tm4c1294_cfg.ld => TM4C1294NCPDT_cfg.ld} | 0 project/cmake/gcc-linux-toolchain.cmake | 31 +++ project/cmake/gcc-toolchain.cmake | 58 +++++ project/cmake/gcc-win-toolchain.cmake | 28 +++ project/cmake/project.cmake | 4 +- project/cmake/ti-toolchain-epilog.cmake | 7 + project/cmake/toolchain-epilog.cmake | 14 ++ project/cmake/toolchain.cmake | 74 +----- utils/start_gdb.ps1 | 2 + utils/start_openocd.ps1 | 7 + utils/start_openocd.sh | 5 +- 23 files changed, 503 insertions(+), 115 deletions(-) delete mode 100644 .vscode/.cortex-debug.registers.state.json create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json rename project/BSP/src/{startup_gcc.c => startup_gcc_tm4c123gh6pm.c} (99%) create mode 100644 project/BSP/src/startup_gcc_tm4c1294ncpdt.c create mode 100644 project/cmake/TM4C123GH6PM_cfg.ld rename project/cmake/{tm4c1294_cfg.ld => TM4C1294NCPDT_cfg.ld} (100%) create mode 100644 project/cmake/gcc-linux-toolchain.cmake create mode 100644 project/cmake/gcc-toolchain.cmake create mode 100644 project/cmake/gcc-win-toolchain.cmake create mode 100644 project/cmake/ti-toolchain-epilog.cmake create mode 100644 project/cmake/toolchain-epilog.cmake create mode 100644 utils/start_gdb.ps1 create mode 100644 utils/start_openocd.ps1 diff --git a/.vscode/.cortex-debug.registers.state.json b/.vscode/.cortex-debug.registers.state.json deleted file mode 100644 index 0637a08..0000000 --- a/.vscode/.cortex-debug.registers.state.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..6ee95a1 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,20 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**", + "C:/ti/tivaware_c_series_2_1_4_178/", + "C:/ti/ccs1281/ccs/tools/compiler/ti-cgt-arm_20.2.7.LTS/include/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE", + "PART_TM4C123GH6PM", + "TARGET_IS_TM4C123_RB1" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 69dfed7..4d57f67 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,16 +7,17 @@ { "name": "Cortex Debug", "cwd": "${workspaceRoot}", - "executable": "./output/output.elf", + "executable": "./build/bin/template.elf", "request": "launch", "type": "cortex-debug", "servertype": "openocd", "searchDir": [ "${workspaceRoot}", - "/usr/share/openocd/scripts/board/", + // "/usr/share/openocd/scripts/board/", + "D:/opt/openocd-v0.12.0-i686-w64-mingw32/share/openocd/scripts/board/", ], "configFiles": [ - "ti_ek-tm4c1294xl.cfg" + "ti_ek-tm4c123gxl.cfg" ] } ] diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e53fdec --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "*.h": "c", + "*.c": "c" + } +} \ No newline at end of file diff --git a/project/BSP/CMakeLists.txt b/project/BSP/CMakeLists.txt index 1b3db51..17f3ea0 100644 --- a/project/BSP/CMakeLists.txt +++ b/project/BSP/CMakeLists.txt @@ -18,7 +18,8 @@ set(BSP_EXEC_ENTRY_POINT ResetISR PARENT_SCOPE) add_library(${COMPONENT_NAME} STATIC ${CMAKE_CURRENT_LIST_DIR}/src/Board.c - ${CMAKE_CURRENT_LIST_DIR}/src/startup_gcc.c + ${CMAKE_CURRENT_LIST_DIR}/src/startup_gcc_tm4c123gh6pm.c + ${CMAKE_CURRENT_LIST_DIR}/src/startup_gcc_tm4c1294ncpdt.c ) target_include_directories(${COMPONENT_NAME} PUBLIC diff --git a/project/BSP/src/Board.c b/project/BSP/src/Board.c index 733c234..e2748cb 100644 --- a/project/BSP/src/Board.c +++ b/project/BSP/src/Board.c @@ -10,23 +10,31 @@ #include "FreeRTOSConfig.h" void Board_init(){ - SysCtlClockFreqSet( (SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | - SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), - SYSTEM_CLOCK ); + ROM_FPUEnable(); + ROM_FPULazyStackingEnable(); + + #if 0 + // Set Clock to 120Mhz on TM4C1294 + SysCtlClockFreqSet( (SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | + SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), + SYSTEM_CLOCK ); + #else + // Set Clock to 80Mhz using PIOSC (on TM4C123G) + ROM_SysCtlClockSet( SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_INT ); + + // Set Clock to 80Mhz using MOSC (on TM4C123G) + // ROM_SysCtlClockSet( SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); + #endif + // // Enable the GPIO port that is used for the on-board LED. - // - SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); - SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); + // (TM4C123GXL board) + SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Check if the peripheral access is enabled. - // - while( - (!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION)) || - (!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOA)) - ) + // (TM4C123GXL board) + while( (!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF)) ) { } - } diff --git a/project/BSP/src/startup_gcc.c b/project/BSP/src/startup_gcc_tm4c123gh6pm.c similarity index 99% rename from project/BSP/src/startup_gcc.c rename to project/BSP/src/startup_gcc_tm4c123gh6pm.c index e2cfed7..a728c13 100644 --- a/project/BSP/src/startup_gcc.c +++ b/project/BSP/src/startup_gcc_tm4c123gh6pm.c @@ -1,5 +1,7 @@ #include +#if PART_TM4C123GH6PM + void ResetISR(void); static void NmiSR(void); static void FaultISR(void); @@ -232,4 +234,4 @@ static void IntDefaultHandler(void) } } - +#endif diff --git a/project/BSP/src/startup_gcc_tm4c1294ncpdt.c b/project/BSP/src/startup_gcc_tm4c1294ncpdt.c new file mode 100644 index 0000000..1768d90 --- /dev/null +++ b/project/BSP/src/startup_gcc_tm4c1294ncpdt.c @@ -0,0 +1,238 @@ +#include + +#if PART_TM4C129XNCZAD + +void ResetISR(void); +static void NmiSR(void); +static void FaultISR(void); +static void IntDefaultHandler(void); + +extern int main( int argc, char *argv[] ); + +extern void xPortPendSVHandler( void ); +extern void xPortSysTickHandler( void ); +extern void vPortSVCHandler( void ); + +extern unsigned long _stack_top; + +__attribute__ ((section(".isr_vector"))) +void (* const g_pfnVectors[])(void) = +{ + (void (*)(void))((unsigned long)&_stack_top), + // The initial stack pointer + ResetISR, // The reset handler + NmiSR, // The NMI handler + FaultISR, // The hard fault handler + IntDefaultHandler, // The MPU fault handler + IntDefaultHandler, // The bus fault handler + IntDefaultHandler, // The usage fault handler + 0, // Reserved + 0, // Reserved + 0, // Reserved + 0, // Reserved + vPortSVCHandler, // SVCall handler + IntDefaultHandler, // Debug monitor handler + 0, // Reserved + xPortPendSVHandler, // The PendSV handler + xPortSysTickHandler, // The SysTick handler + IntDefaultHandler, // GPIO Port A + IntDefaultHandler, // GPIO Port B + IntDefaultHandler, // GPIO Port C + IntDefaultHandler, // GPIO Port D + IntDefaultHandler, // GPIO Port E + IntDefaultHandler, // UART0 Rx and Tx + IntDefaultHandler, // UART1 Rx and Tx + IntDefaultHandler, // SSI0 Rx and Tx + IntDefaultHandler, // I2C0 Master and Slave + IntDefaultHandler, // PWM Fault + IntDefaultHandler, // PWM Generator 0 + IntDefaultHandler, // PWM Generator 1 + IntDefaultHandler, // PWM Generator 2 + IntDefaultHandler, // Quadrature Encoder 0 + IntDefaultHandler, // ADC Sequence 0 + IntDefaultHandler, // ADC Sequence 1 + IntDefaultHandler, // ADC Sequence 2 + IntDefaultHandler, // ADC Sequence 3 + IntDefaultHandler, // Watchdog timer + IntDefaultHandler, // Timer 0 subtimer A + IntDefaultHandler, // Timer 0 subtimer B + IntDefaultHandler, // Timer 1 subtimer A + IntDefaultHandler, // Timer 1 subtimer B + IntDefaultHandler, // Timer 2 subtimer A + IntDefaultHandler, // Timer 2 subtimer B + IntDefaultHandler, // Analog Comparator 0 + IntDefaultHandler, // Analog Comparator 1 + IntDefaultHandler, // Analog Comparator 2 + IntDefaultHandler, // System Control (PLL, OSC, BO) + IntDefaultHandler, // FLASH Control + IntDefaultHandler, // GPIO Port F + IntDefaultHandler, // GPIO Port G + IntDefaultHandler, // GPIO Port H + IntDefaultHandler, // UART2 Rx and Tx + IntDefaultHandler, // SSI1 Rx and Tx + IntDefaultHandler, // Timer 3 subtimer A + IntDefaultHandler, // Timer 3 subtimer B + IntDefaultHandler, // I2C1 Master and Slave + IntDefaultHandler, // CAN0 + IntDefaultHandler, // CAN1 + IntDefaultHandler, // Ethernet + IntDefaultHandler, // Hibernate + IntDefaultHandler, // USB0 + IntDefaultHandler, // PWM Generator 3 + IntDefaultHandler, // uDMA Software Transfer + IntDefaultHandler, // uDMA Error + IntDefaultHandler, // ADC1 Sequence 0 + IntDefaultHandler, // ADC1 Sequence 1 + IntDefaultHandler, // ADC1 Sequence 2 + IntDefaultHandler, // ADC1 Sequence 3 + IntDefaultHandler, // External Bus Interface 0 + IntDefaultHandler, // GPIO Port J + IntDefaultHandler, // GPIO Port K + IntDefaultHandler, // GPIO Port L + IntDefaultHandler, // SSI2 Rx and Tx + IntDefaultHandler, // SSI3 Rx and Tx + IntDefaultHandler, // UART3 Rx and Tx + IntDefaultHandler, // UART4 Rx and Tx + IntDefaultHandler, // UART5 Rx and Tx + IntDefaultHandler, // UART6 Rx and Tx + IntDefaultHandler, // UART7 Rx and Tx + IntDefaultHandler, // I2C2 Master and Slave + IntDefaultHandler, // I2C3 Master and Slave + IntDefaultHandler, // Timer 4 subtimer A + IntDefaultHandler, // Timer 4 subtimer B + IntDefaultHandler, // Timer 5 subtimer A + IntDefaultHandler, // Timer 5 subtimer B + IntDefaultHandler, // FPU + 0, // Reserved + 0, // Reserved + IntDefaultHandler, // I2C4 Master and Slave + IntDefaultHandler, // I2C5 Master and Slave + IntDefaultHandler, // GPIO Port M + IntDefaultHandler, // GPIO Port N + 0, // Reserved + IntDefaultHandler, // Tamper + IntDefaultHandler, // GPIO Port P (Summary or P0) + IntDefaultHandler, // GPIO Port P1 + IntDefaultHandler, // GPIO Port P2 + IntDefaultHandler, // GPIO Port P3 + IntDefaultHandler, // GPIO Port P4 + IntDefaultHandler, // GPIO Port P5 + IntDefaultHandler, // GPIO Port P6 + IntDefaultHandler, // GPIO Port P7 + IntDefaultHandler, // GPIO Port Q (Summary or Q0) + IntDefaultHandler, // GPIO Port Q1 + IntDefaultHandler, // GPIO Port Q2 + IntDefaultHandler, // GPIO Port Q3 + IntDefaultHandler, // GPIO Port Q4 + IntDefaultHandler, // GPIO Port Q5 + IntDefaultHandler, // GPIO Port Q6 + IntDefaultHandler, // GPIO Port Q7 + IntDefaultHandler, // GPIO Port R + IntDefaultHandler, // GPIO Port S + IntDefaultHandler, // SHA/MD5 0 + IntDefaultHandler, // AES 0 + IntDefaultHandler, // DES3DES 0 + IntDefaultHandler, // LCD Controller 0 + IntDefaultHandler, // Timer 6 subtimer A + IntDefaultHandler, // Timer 6 subtimer B + IntDefaultHandler, // Timer 7 subtimer A + IntDefaultHandler, // Timer 7 subtimer B + IntDefaultHandler, // I2C6 Master and Slave + IntDefaultHandler, // I2C7 Master and Slave + IntDefaultHandler, // HIM Scan Matrix Keyboard 0 + IntDefaultHandler, // One Wire 0 + IntDefaultHandler, // HIM PS/2 0 + IntDefaultHandler, // HIM LED Sequencer 0 + IntDefaultHandler, // HIM Consumer IR 0 + IntDefaultHandler, // I2C8 Master and Slave + IntDefaultHandler, // I2C9 Master and Slave + IntDefaultHandler // GPIO Port T +}; + +//***************************************************************************** +// +// The following are constructs created by the linker, indicating where the +// the "data" and "bss" segments reside in memory. The initializers for the +// for the "data" segment resides immediately following the "text" segment. +// +//***************************************************************************** +extern unsigned long _text; +extern unsigned long _etext; +extern unsigned long _data; +extern unsigned long _edata; +extern unsigned long _bss; +extern unsigned long _ebss; + +//***************************************************************************** +// +// This is the code that gets called when the processor first starts execution +// following a reset event. Only the absolutely necessary set is performed, +// after which the application supplied entry() routine is called. Any fancy +// actions (such as making decisions based on the reset cause register, and +// resetting the bits in that register) are left solely in the hands of the +// application. +// +//***************************************************************************** + +void ResetISR(void) +{ + + unsigned long *pulSrc, *pulDest; + pulSrc = &_etext; + for(pulDest = &_data; pulDest < &_edata; ) + { + *pulDest++ = *pulSrc++; + } + + for(pulDest = &_bss; pulDest < &_ebss; ) + { + *pulDest++ = 0; + } + + main( 0x00U , 0x00U ); +} + +//***************************************************************************** +// +// This is the code that gets called when the processor receives a NMI. This +// simply enters an infinite loop, preserving the system state for examination +// by a debugger. +// +//***************************************************************************** +static void NmiSR(void) +{ + while(1) + { + } +} + +//***************************************************************************** +// +// This is the code that gets called when the processor receives a fault +// interrupt. This simply enters an infinite loop, preserving the system state +// for examination by a debugger. +// +//***************************************************************************** +static void FaultISR(void) +{ + while(1) + { + } +} + +//***************************************************************************** +// +// This is the code that gets called when the processor receives an unexpected +// interrupt. This simply enters an infinite loop, preserving the system state +// for examination by a debugger. +// +//***************************************************************************** +static void IntDefaultHandler(void) +{ + while(1) + { + } +} + + +#endif diff --git a/project/CMakeLists.txt b/project/CMakeLists.txt index 9598ee7..bd062db 100644 --- a/project/CMakeLists.txt +++ b/project/CMakeLists.txt @@ -14,6 +14,8 @@ project( TivaCTemplate LANGUAGES C ASM ) +include(cmake/toolchain-epilog.cmake) + # =================================================================== # Project Set-Up # =================================================================== diff --git a/project/Tasks/CMakeLists.txt b/project/Tasks/CMakeLists.txt index 717c1ae..366eb6b 100644 --- a/project/Tasks/CMakeLists.txt +++ b/project/Tasks/CMakeLists.txt @@ -19,12 +19,5 @@ target_link_libraries( ${COMPONENT_NAME} TivaWare Misc System - I2C::TivaCTM4C1294 - SPI::TivaCTM4C1294 - BUS8080::TivaCTM4C1294 - ILI9341::TivaCTM4C1294 - SSD1306::TivaCTM4C1294 - MCP2515::TivaCTM4C1294 - simpleGFX::TivaCTM4C1294 ) diff --git a/project/Tasks/src/Tasks.c b/project/Tasks/src/Tasks.c index a81e6e1..e691a5d 100644 --- a/project/Tasks/src/Tasks.c +++ b/project/Tasks/src/Tasks.c @@ -26,38 +26,34 @@ void Tasks_init( void ){ void demoTask1(void *pvArg) { + const uint32_t ms_period = 125/portTICK_PERIOD_MS; + const uint32_t port = GPIO_PORTF_BASE; + const uint8_t pin = GPIO_PIN_1;// TM4C123GXL board, Red Led // // Enable the GPIO pin for the LED (PN0). Set the direction as output, and // enable the GPIO pin for digital function. // - GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); - GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_0); + GPIOPinTypeGPIOOutput(port, pin); for (;;) { - GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0); - GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_0, GPIO_PIN_0); - vTaskDelay(125 / portTICK_PERIOD_MS); - GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x00); - GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_0, 0x00); - vTaskDelay(125 / portTICK_PERIOD_MS); + GPIOPinWrite(port, pin, ~GPIOPinRead( port, pin ) ); + vTaskDelay(ms_period); } } void demoTask2(void *pvArg) { + const uint32_t ms_period = 250/portTICK_PERIOD_MS; + const uint32_t port = GPIO_PORTF_BASE; + const uint8_t pin = GPIO_PIN_2;// TM4C123GXL board, Blue Led // // Enable the GPIO pin for the LED (PN0). Set the direction as output, and // enable the GPIO pin for digital function. // - GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1); - GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_1); + GPIOPinTypeGPIOOutput(port, pin); for (;;) { - GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, GPIO_PIN_1); - GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_1, GPIO_PIN_1); - vTaskDelay(250 / portTICK_PERIOD_MS); - GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x00); - GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_1, 0x00); - vTaskDelay(250 / portTICK_PERIOD_MS); + GPIOPinWrite(port, pin, ~GPIOPinRead( port, pin ) ); + vTaskDelay(ms_period); } } diff --git a/project/cmake/TM4C123GH6PM_cfg.ld b/project/cmake/TM4C123GH6PM_cfg.ld new file mode 100644 index 0000000..c3aa397 --- /dev/null +++ b/project/cmake/TM4C123GH6PM_cfg.ld @@ -0,0 +1,40 @@ +#define CODE_BASE 0x00000000 +#define CODE_SIZE 256K +#define SRAM_BASE 0x20000000 +#define SRAM_SIZE 32K + +MEMORY +{ + FLASH (rx): ORIGIN = CODE_BASE, LENGTH = CODE_SIZE + SRAM (rwx) : ORIGIN = SRAM_BASE, LENGTH = SRAM_SIZE +} + +SECTIONS +{ + .text : + { + _text = .; + KEEP(*(.isr_vector)) + *(.text*) + *(.rodata*) + _etext = .; + } > FLASH + + .data : AT(ADDR(.text) + SIZEOF(.text)) + { + _data = .; + *(vtable) + *(.data*) + _edata = .; + } > SRAM + + .bss : + { + _bss = .; + *(.bss*) + *(COMMON) + _ebss = .; + } > SRAM +} + +_stack_top = ORIGIN(SRAM) + LENGTH(SRAM); diff --git a/project/cmake/tm4c1294_cfg.ld b/project/cmake/TM4C1294NCPDT_cfg.ld similarity index 100% rename from project/cmake/tm4c1294_cfg.ld rename to project/cmake/TM4C1294NCPDT_cfg.ld diff --git a/project/cmake/gcc-linux-toolchain.cmake b/project/cmake/gcc-linux-toolchain.cmake new file mode 100644 index 0000000..bed2f41 --- /dev/null +++ b/project/cmake/gcc-linux-toolchain.cmake @@ -0,0 +1,31 @@ +################################################################################ +# @file CMakeLists.txt +# @author Josepablo C (josepablo134@gmail.com) +# @version 1.0 +################################################################################ + +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR ARM) + +set(TOOLCHAIN arm-none-eabi) +set(TOOLCHAIN_PREFIX "/usr") +set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/bin) +set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/include) +set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/lib) + +# Perform compiler test with static library +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +#--------------------------------------------------------------------------------------- +# Set compilers +#--------------------------------------------------------------------------------------- +set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc CACHE INTERNAL "C Compiler") +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-g++ CACHE INTERNAL "C++ Compiler") +set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc CACHE INTERNAL "ASM Compiler") +set(CMAKE_OBJCOPY ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-objcopy CACHE INTERNAL "ObjCopy") + +set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${TOOLCHAIN} ${CMAKE_PREFIX_PATH}) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/project/cmake/gcc-toolchain.cmake b/project/cmake/gcc-toolchain.cmake new file mode 100644 index 0000000..cd4f2d5 --- /dev/null +++ b/project/cmake/gcc-toolchain.cmake @@ -0,0 +1,58 @@ +################################################################################ +# @file CMakeLists.txt +# @author Josepablo C (josepablo134@gmail.com) +# @version 1.0 +################################################################################ + +if (WIN32) + message("Windows detected") + include(${CMAKE_CURRENT_LIST_DIR}/gcc-win-toolchain.cmake) +else () + include(${CMAKE_CURRENT_LIST_DIR}/gcc-linux-toolchain.cmake) +endif () + +set(TOOLCHAIN_COMPILER_GCC_TYPE "GCC" CACHE INTERNAL "Determines the type of compiler configured with this toolchain script for the epilog") + +#--------------------------------------------------------------------------------------- +# Set compiler/linker flags +#--------------------------------------------------------------------------------------- + +# Object build options +# -O0 No optimizations, reduce compilation time and make debugging produce the expected results. +# -mthumb Generat thumb instructions. +# -fno-builtin Do not use built-in functions provided by GCC. +# -Wall Print only standard warnings, for all use Wextra +# -ffunction-sections Place each function item into its own section in the output file. +# -fdata-sections Place each data item into its own section in the output file. +# -fomit-frame-pointer Omit the frame pointer in functions that don’t need one. +# -mabi=aapcs Defines enums to be a variable sized type. +set(OBJECT_GEN_FLAGS "-O0 -mthumb -fno-builtin -Wall -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-exceptions -nostartfiles -g3 -gdwarf-2 -lgcc -lc -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DTARGET_IS_TM4C123_RB1 -DPART_TM4C123GH6PM -Dgcc") + +set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} -std=gnu99 " CACHE INTERNAL "C Compiler options") +set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} -std=c++11 " CACHE INTERNAL "C++ Compiler options") +set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} -x assembler-with-cpp " CACHE INTERNAL "ASM Compiler options") + +# -Wl,--gc-sections Perform the dead code elimination. +# --specs=nano.specs Link with newlib-nano. +# --specs=nosys.specs No syscalls, provide empty implementations for the POSIX system calls. +set(CMAKE_EXE_LINKER_FLAGS "--specs=nano.specs --specs=nosys.specs -mthumb -mabi=aapcs -fno-exceptions -nostartfiles -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -lgcc -lc -Wl,--gc-sections -Wl,-n" CACHE INTERNAL "Linker options") + +#--------------------------------------------------------------------------------------- +# Set debug/release build configuration Options +#--------------------------------------------------------------------------------------- + +# Options for DEBUG build +# -Og Enables optimizations that do not interfere with debugging. +# -g Produce debugging information in the operating system’s native format. +set(CMAKE_C_FLAGS_DEBUG "-Og -g" CACHE INTERNAL "C Compiler options for debug build type") +set(CMAKE_CXX_FLAGS_DEBUG "-Og -g" CACHE INTERNAL "C++ Compiler options for debug build type") +set(CMAKE_ASM_FLAGS_DEBUG "-g" CACHE INTERNAL "ASM Compiler options for debug build type") +set(CMAKE_EXE_LINKER_FLAGS_DEBUG "" CACHE INTERNAL "Linker options for debug build type") + +# Options for RELEASE build +# -Os Optimize for size. -Os enables all -O2 optimizations. +# -flto Runs the standard link-time optimizer. +set(CMAKE_C_FLAGS_RELEASE "-Os -flto" CACHE INTERNAL "C Compiler options for release build type") +set(CMAKE_CXX_FLAGS_RELEASE "-Os -flto" CACHE INTERNAL "C++ Compiler options for release build type") +set(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "ASM Compiler options for release build type") +set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-flto" CACHE INTERNAL "Linker options for release build type") diff --git a/project/cmake/gcc-win-toolchain.cmake b/project/cmake/gcc-win-toolchain.cmake new file mode 100644 index 0000000..0c2dfec --- /dev/null +++ b/project/cmake/gcc-win-toolchain.cmake @@ -0,0 +1,28 @@ +################################################################################ +# @file CMakeLists.txt +# @author Josepablo C (josepablo134@gmail.com) +# @version 1.0 +################################################################################ + +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR ARM) + +set(TOOLCHAIN arm-none-eabi) +set(TOOLCHAIN_PREFIX "C:/Program Files (x86)/Arm GNU Toolchain arm-none-eabi/13.3 rel1") +set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/bin) +set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/include) +set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/lib) + +#--------------------------------------------------------------------------------------- +# Set compilers +#--------------------------------------------------------------------------------------- +set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc.exe CACHE INTERNAL "C Compiler") +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-g++.exe CACHE INTERNAL "C++ Compiler") +set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc.exe CACHE INTERNAL "ASM Compiler") +set(CMAKE_OBJCOPY ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-objcopy.exe CACHE INTERNAL "Object copy") + +set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${TOOLCHAIN} ${CMAKE_PREFIX_PATH}) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/project/cmake/project.cmake b/project/cmake/project.cmake index 1030e76..e068f56 100644 --- a/project/cmake/project.cmake +++ b/project/cmake/project.cmake @@ -13,6 +13,6 @@ set( OUTPUT_S19 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${EXEC_NAME}.s19) set( OUTPUT_HEX ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${EXEC_NAME}.hex) set( OUTPUT_MAP ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${EXEC_NAME}.map) -set( PRE_LINKER_SCRIPT ${WORK_DIR}/cmake/tm4c1294_cfg.ld) -set( LINKER_SCRIPT ${CMAKE_RUNTIME_LOCATE_DIRECTORY}/tm4c1294.ld) +set( PRE_LINKER_SCRIPT ${WORK_DIR}/cmake/TM4C123GH6PM_cfg.ld) +set( LINKER_SCRIPT ${CMAKE_RUNTIME_LOCATE_DIRECTORY}/linkerscript.ld) diff --git a/project/cmake/ti-toolchain-epilog.cmake b/project/cmake/ti-toolchain-epilog.cmake new file mode 100644 index 0000000..44d510b --- /dev/null +++ b/project/cmake/ti-toolchain-epilog.cmake @@ -0,0 +1,7 @@ +################################################################################ +# @file CMakeLists.txt +# @author Josepablo C (josepablo134@gmail.com) +# @version 1.0 +################################################################################ + +message("Nothing to do") diff --git a/project/cmake/toolchain-epilog.cmake b/project/cmake/toolchain-epilog.cmake new file mode 100644 index 0000000..3beaeb8 --- /dev/null +++ b/project/cmake/toolchain-epilog.cmake @@ -0,0 +1,14 @@ +################################################################################ +# @file CMakeLists.txt +# @author Josepablo C (josepablo134@gmail.com) +# @version 1.0 +################################################################################ + +IF(TOOLCHAIN_COMPILER_GCC_TYPE) + message("TOOLCHAIN EPILOG: GCC Detected - Nothing to do") +elseif (TOOLCHAIN_COMPILER_TI_TYPE) + message("TOOLCHAIN EPILOG: Texas Instrument Detected") + include(${CMAKE_CURRENT_LIST_DIR}/ti-toolchain-epilog.cmake) +else() + message(FATAL_ERROR "TOOLCHAIN EPILOG: Toolchain mode not detected!" ) +endif () diff --git a/project/cmake/toolchain.cmake b/project/cmake/toolchain.cmake index 45bf00c..f250640 100644 --- a/project/cmake/toolchain.cmake +++ b/project/cmake/toolchain.cmake @@ -4,75 +4,7 @@ # @version 1.0 ################################################################################ -set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_PROCESSOR ARM) - -set(TOOLCHAIN arm-none-eabi) -set(TOOLCHAIN_PREFIX "/usr") -set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/bin) -set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/include) -set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/${TOOLCHAIN}/lib) - -# Perform compiler test with static library -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) - -#--------------------------------------------------------------------------------------- -# Set compiler/linker flags -#--------------------------------------------------------------------------------------- - -# Object build options -# -O0 No optimizations, reduce compilation time and make debugging produce the expected results. -# -mthumb Generat thumb instructions. -# -fno-builtin Do not use built-in functions provided by GCC. -# -Wall Print only standard warnings, for all use Wextra -# -ffunction-sections Place each function item into its own section in the output file. -# -fdata-sections Place each data item into its own section in the output file. -# -fomit-frame-pointer Omit the frame pointer in functions that don’t need one. -# -mabi=aapcs Defines enums to be a variable sized type. -set(OBJECT_GEN_FLAGS "-O0 -mthumb -fno-builtin -Wall -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-exceptions -nostartfiles -g3 -gdwarf-2 -lgcc -lc -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DTARGET_IS_TM4C129_RA1 -DPART_TM4C129XNCZAD -Dgcc") - -set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} -std=gnu99 " CACHE INTERNAL "C Compiler options") -set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} -std=c++11 " CACHE INTERNAL "C++ Compiler options") -set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} -x assembler-with-cpp " CACHE INTERNAL "ASM Compiler options") - -# -Wl,--gc-sections Perform the dead code elimination. -# --specs=nano.specs Link with newlib-nano. -# --specs=nosys.specs No syscalls, provide empty implementations for the POSIX system calls. -set(CMAKE_EXE_LINKER_FLAGS "--specs=nano.specs --specs=nosys.specs -mthumb -mabi=aapcs -fno-exceptions -nostartfiles -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -lgcc -lc -Wl,--gc-sections -Wl,-n" CACHE INTERNAL "Linker options") - -#--------------------------------------------------------------------------------------- -# Set debug/release build configuration Options -#--------------------------------------------------------------------------------------- - -# Options for DEBUG build -# -Og Enables optimizations that do not interfere with debugging. -# -g Produce debugging information in the operating system’s native format. -set(CMAKE_C_FLAGS_DEBUG "-Og -g" CACHE INTERNAL "C Compiler options for debug build type") -set(CMAKE_CXX_FLAGS_DEBUG "-Og -g" CACHE INTERNAL "C++ Compiler options for debug build type") -set(CMAKE_ASM_FLAGS_DEBUG "-g" CACHE INTERNAL "ASM Compiler options for debug build type") -set(CMAKE_EXE_LINKER_FLAGS_DEBUG "" CACHE INTERNAL "Linker options for debug build type") - -# Options for RELEASE build -# -Os Optimize for size. -Os enables all -O2 optimizations. -# -flto Runs the standard link-time optimizer. -set(CMAKE_C_FLAGS_RELEASE "-Os -flto" CACHE INTERNAL "C Compiler options for release build type") -set(CMAKE_CXX_FLAGS_RELEASE "-Os -flto" CACHE INTERNAL "C++ Compiler options for release build type") -set(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "ASM Compiler options for release build type") -set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-flto" CACHE INTERNAL "Linker options for release build type") - - -#--------------------------------------------------------------------------------------- -# Set compilers -#--------------------------------------------------------------------------------------- -set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc CACHE INTERNAL "C Compiler") -set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-g++ CACHE INTERNAL "C++ Compiler") -set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc CACHE INTERNAL "ASM Compiler") -set(CMAKE_OBJCOPY ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-objcopy CACHE INTERNAL "ObjCopy") - -set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${TOOLCHAIN} ${CMAKE_PREFIX_PATH}) -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) - +# Enable the line that set up your preferred toolchain +include(${CMAKE_CURRENT_LIST_DIR}/gcc-toolchain.cmake) +# include(${CMAKE_CURRENT_LIST_DIR}/ti-toolchain.cmake) diff --git a/utils/start_gdb.ps1 b/utils/start_gdb.ps1 new file mode 100644 index 0000000..9d1c235 --- /dev/null +++ b/utils/start_gdb.ps1 @@ -0,0 +1,2 @@ + +arm-none-eabi-gdb --command gdb.cmd diff --git a/utils/start_openocd.ps1 b/utils/start_openocd.ps1 new file mode 100644 index 0000000..f8f8148 --- /dev/null +++ b/utils/start_openocd.ps1 @@ -0,0 +1,7 @@ +$ENV:OPENOCD_PATH="D:\opt\openocd-v0.12.0-i686-w64-mingw32\" +$ENV:BOARD="ti_ek-tm4c123gxl.cfg" +# $ENV:BOARD="ti_ek-tm4c1294xl.cfg" + +echo "Loading file $ENV:OPENOCD_PATH/share/openocd/scripts/board/$ENV:BOARD" + +openocd -f "$ENV:OPENOCD_PATH/share/openocd/scripts/board/$ENV:BOARD" diff --git a/utils/start_openocd.sh b/utils/start_openocd.sh index b76b1c2..7eab2e6 100755 --- a/utils/start_openocd.sh +++ b/utils/start_openocd.sh @@ -1,3 +1,6 @@ #! /bin/bash -openocd -f /usr/share/openocd/scripts/board/ti_ek-tm4c1294xl.cfg +$BOARD="ti_ek-tm4c123gxl.cfg" +# $BOARD="ti_ek-tm4c1294xl.cfg" + +openocd -f /usr/share/openocd/scripts/board/$BOARD