├── Documents ├── CortexM3-generic-user-guide.pdf └── CortexM4-generic-user-guide.pdf ├── Emebdded_system_programming_on_CortexM3M4.pdf ├── README.md ├── Source_code ├── 001_HelloWorld │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── HelloWorld Debug.cfg │ ├── HelloWorld Debug.launch │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ └── Startup │ │ └── startup_stm32f407vgtx.s ├── 002_HelloWorld_semihosting │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── HelloWorld_semihosting Debug.cfg │ ├── HelloWorld_semihosting Debug.launch │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ └── Startup │ │ └── startup_stm32f407vgtx.s ├── 003_operation_modes │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ ├── Startup │ │ └── startup_stm32f407vgtx.s │ └── operation_modes Debug.launch ├── 004_inline_1 │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ ├── Startup │ │ └── startup_stm32f407vgtx.s │ └── inline_1 Debug.launch ├── 005_access_levels │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ ├── Startup │ │ └── startup_stm32f407vgtx.s │ └── access_levels Debug.launch ├── 006_t-bit │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ ├── Startup │ │ └── startup_stm32f407vgtx.s │ └── t-bit Debug.launch ├── 007_bit_banding │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ ├── Startup │ │ └── startup_stm32f407vgtx.s │ └── bit_banding Debug.launch ├── 008_stack │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ ├── Startup │ │ └── startup_stm32f407vgtx.s │ └── stack Debug.launch ├── 009_USART3_int_pend │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ ├── Startup │ │ └── startup_stm32f407vgtx.s │ └── USART3_int_pend Debug.launch ├── 010_interrupt_priority │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ ├── Startup │ │ └── startup_stm32f407vgtx.s │ └── interrupt_priority Debug.launch ├── 011_exception_entry_exit │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ ├── Startup │ │ └── startup_stm32f407vgtx.s │ └── exception_entry_exit Debug.launch ├── 012_fault_gen │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── main-1.c │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ ├── Startup │ │ └── startup_stm32f407vgtx.s │ └── fault_gen Debug.launch ├── 013_svc_number │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ ├── Startup │ │ └── startup_stm32f407vgtx.s │ ├── svc_number Debug.cfg │ └── svc_number Debug.launch ├── 014_svc_operation │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ ├── Startup │ │ └── startup_stm32f407vgtx.s │ └── svc_operation Debug.launch ├── 015_task_scheduler │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── Inc │ │ ├── led.h │ │ └── main.h │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── led.c │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ ├── Startup │ │ └── startup_stm32f407vgtx.s │ └── task_scheduler Debug.launch ├── 016_cmsis_task_scheduler │ ├── .cproject │ ├── .project │ ├── .settings │ │ └── language.settings.xml │ ├── Inc │ │ ├── led.h │ │ └── main.h │ ├── STM32F407VGTX_FLASH.ld │ ├── STM32F407VGTX_RAM.ld │ ├── Src │ │ ├── led.c │ │ ├── main.c │ │ ├── syscalls.c │ │ └── sysmem.c │ ├── Startup │ │ └── startup_stm32f407vgtx.s │ └── driver │ │ ├── CMSIS │ │ └── Core │ │ │ └── Include │ │ │ ├── cmsis_armcc.h │ │ │ ├── cmsis_armclang.h │ │ │ ├── cmsis_armclang_ltm.h │ │ │ ├── cmsis_compiler.h │ │ │ ├── cmsis_gcc.h │ │ │ ├── cmsis_iccarm.h │ │ │ ├── cmsis_version.h │ │ │ ├── core_armv81mml.h │ │ │ ├── core_armv8mbl.h │ │ │ ├── core_armv8mml.h │ │ │ ├── core_cm0.h │ │ │ ├── core_cm0plus.h │ │ │ ├── core_cm1.h │ │ │ ├── core_cm23.h │ │ │ ├── core_cm3.h │ │ │ ├── core_cm33.h │ │ │ ├── core_cm35p.h │ │ │ ├── core_cm4.h │ │ │ ├── core_cm7.h │ │ │ ├── core_sc000.h │ │ │ ├── core_sc300.h │ │ │ ├── mpu_armv7.h │ │ │ ├── mpu_armv8.h │ │ │ └── tz_context.h │ │ ├── Device │ │ └── ST │ │ │ ├── ReadMe.txt │ │ │ └── ST │ │ │ └── stm32f4xx │ │ │ ├── Include │ │ │ ├── stm32f4xx.h │ │ │ └── system_stm32f4xx.h │ │ │ └── Source │ │ │ ├── GCC │ │ │ └── gcc_arm.ld │ │ │ └── system_stm32f4xx.c │ │ └── LICENSE.txt ├── RemoteSystemsTempFiles │ └── .project ├── mcu_exception_handlr_prototypes └── syscalls.c └── old └── Source_codes └── KEIL-MDK-5 ├── Access_level ├── DebugConfig │ └── Target_1_STM32F407VGTx.dbgconf ├── EventRecorderStub.scvd ├── Objects │ ├── ExtDll.iex │ ├── main.crf │ └── system_stm32f4xx.crf ├── RTE │ ├── Device │ │ └── STM32F407VGTx │ │ │ ├── startup_stm32f407xx.s │ │ │ └── system_stm32f4xx.c │ └── _Target_1 │ │ └── RTE_Components.h ├── main.c ├── switching_access_level.uvguix.kiran ├── switching_access_level.uvoptx └── switching_access_level.uvprojx ├── Operational_mode ├── DebugConfig │ └── Target_1_STM32F407VGTx.dbgconf ├── EventRecorderStub.scvd ├── Objects │ ├── ExtDll.iex │ ├── main.crf │ └── system_stm32f4xx.crf ├── Operational_mode.uvguix.kiran ├── Operational_mode.uvoptx ├── Operational_mode.uvprojx ├── RTE │ ├── Device │ │ └── STM32F407VGTx │ │ │ ├── startup_stm32f407xx.s │ │ │ └── system_stm32f4xx.c │ └── _Target_1 │ │ └── RTE_Components.h └── main.c ├── Reset_Sequence ├── DebugConfig │ └── Target_1_STM32F407VGTx.dbgconf ├── EventRecorderStub.scvd ├── Objects │ ├── ExtDll.iex │ ├── main.crf │ └── system_stm32f4xx.crf ├── RTE │ ├── Device │ │ └── STM32F407VGTx │ │ │ ├── startup_stm32f407xx.s │ │ │ └── system_stm32f4xx.c │ └── _Target_1 │ │ └── RTE_Components.h ├── main.c ├── reset_Sequence.uvguix.kiran ├── reset_Sequence.uvoptx └── reset_Sequence.uvprojx ├── Section 11_ (60) Stacks ├── main.c └── stack_op.s ├── Section 13_ (76) Exception masking & unmasking ├── led.c ├── led.h ├── main.c └── my_board.h ├── Section 13_ (78) Interrupt priority and preemption ├── led.c ├── led.h ├── main.c └── my_board.h ├── Section 15_ (82) Toggle LED using registers └── main.c ├── Section 15_ External Interrupts-Buttons ├── led.c ├── led.h ├── main.c └── my_board.h ├── Section 17_ (80) SVC exception ├── main.c └── svc_handler.s ├── Section 17_ (90) PendSV exception ├── led.c ├── led.h ├── main.c └── my_board.h ├── Section 7_ Access levels ├── led.c ├── led.h ├── main.c └── my_board.h ├── Section 7_ Cortex-M registers └── main.c └── Section 9_ (51) Bit banding └── main.c /Documents/CortexM3-generic-user-guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niekiran/CortexMxProgramming/d2ac2ef41bd7af598de6404adbafc5a5fb7fd34d/Documents/CortexM3-generic-user-guide.pdf -------------------------------------------------------------------------------- /Documents/CortexM4-generic-user-guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niekiran/CortexMxProgramming/d2ac2ef41bd7af598de6404adbafc5a5fb7fd34d/Documents/CortexM4-generic-user-guide.pdf -------------------------------------------------------------------------------- /Emebdded_system_programming_on_CortexM3M4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niekiran/CortexMxProgramming/d2ac2ef41bd7af598de6404adbafc5a5fb7fd34d/Emebdded_system_programming_on_CortexM3M4.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CortexMxProgramming 2 | Repository for Udemy course : Embedded System Programming on ARM Cortex Mx.. 3 | Check all courses here : www.fastbitlab.com -------------------------------------------------------------------------------- /Source_code/001_HelloWorld/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | HelloWorld 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/001_HelloWorld/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/001_HelloWorld/HelloWorld Debug.cfg: -------------------------------------------------------------------------------- 1 | # This is an STM32F407G-DISC1 board with a single STM32F407VGTx chip 2 | # 3 | # Generated by STM32CubeIDE 4 | # Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s) 5 | 6 | 7 | source [find interface/stlink.cfg] 8 | 9 | set WORKAREASIZE 0x8000 10 | 11 | transport select "hla_swd" 12 | 13 | set CHIPNAME STM32F407VGTx 14 | set BOARDNAME STM32F407G-DISC1 15 | 16 | # Enable debug when in low power modes 17 | set ENABLE_LOW_POWER 1 18 | 19 | # Stop Watchdog counters when halt 20 | set STOP_WATCHDOG 1 21 | 22 | # STlink Debug clock frequency 23 | set CLOCK_FREQ 8000 24 | 25 | # Reset configuration 26 | # use hardware reset, connect under reset 27 | # connect_assert_srst needed if low power mode application running (WFI...) 28 | reset_config srst_only srst_nogate connect_assert_srst 29 | set CONNECT_UNDER_RESET 1 30 | set CORE_RESET 0 31 | 32 | # ACCESS PORT NUMBER 33 | set AP_NUM 0 34 | # GDB PORT 35 | set GDB_PORT 3333 36 | 37 | 38 | # BCTM CPU variables 39 | 40 | 41 | 42 | source [find target/stm32f4x.cfg] 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Source_code/001_HelloWorld/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @version V1.0 6 | * @brief Default main function. 7 | ****************************************************************************** 8 | */ 9 | 10 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 11 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 12 | #endif 13 | 14 | #include 15 | 16 | int main(void) 17 | { 18 | /* This message is going to be displayed on SWV ITM data console of the IDE. 19 | * Make sure the message terminates with '\n' character. 20 | * syscalls.c must contain code given in the below link 21 | * https://github.com/niekiran/Embedded-C/blob/master/All_source_codes/target/itm_send_data.c 22 | */ 23 | printf("Hello world\n"); 24 | 25 | for(;;); 26 | } 27 | -------------------------------------------------------------------------------- /Source_code/001_HelloWorld/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/002_HelloWorld_semihosting/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | HelloWorld_semihosting 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/002_HelloWorld_semihosting/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/002_HelloWorld_semihosting/HelloWorld_semihosting Debug.cfg: -------------------------------------------------------------------------------- 1 | # This is an STM32F407G-DISC1 board with a single STM32F407VGTx chip 2 | # 3 | # Generated by STM32CubeIDE 4 | # Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s) 5 | 6 | 7 | source [find interface/stlink.cfg] 8 | 9 | set WORKAREASIZE 0x8000 10 | 11 | transport select "hla_swd" 12 | 13 | set CHIPNAME STM32F407VGTx 14 | set BOARDNAME STM32F407G-DISC1 15 | 16 | # Enable debug when in low power modes 17 | set ENABLE_LOW_POWER 1 18 | 19 | # Stop Watchdog counters when halt 20 | set STOP_WATCHDOG 1 21 | 22 | # STlink Debug clock frequency 23 | set CLOCK_FREQ 8000 24 | 25 | # Reset configuration 26 | # use hardware reset, connect under reset 27 | # connect_assert_srst needed if low power mode application running (WFI...) 28 | reset_config srst_only srst_nogate connect_assert_srst 29 | set CONNECT_UNDER_RESET 1 30 | set CORE_RESET 0 31 | 32 | # ACCESS PORT NUMBER 33 | set AP_NUM 0 34 | # GDB PORT 35 | set GDB_PORT 3333 36 | 37 | 38 | # BCTM CPU variables 39 | 40 | 41 | 42 | source [find target/stm32f4x.cfg] 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Source_code/002_HelloWorld_semihosting/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @version V1.0 6 | * @brief Default main function. 7 | ****************************************************************************** 8 | */ 9 | 10 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 11 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 12 | #endif 13 | 14 | #include 15 | 16 | extern void initialise_monitor_handles(void); 17 | 18 | int main(void) 19 | { 20 | /* This message is going to be displayed via OpenOCD semihosting. 21 | * Make sure the message terminates with '\n' character. 22 | * set the linker arguments 23 | * -specs=rdimon.specs -lc -lrdimon 24 | * Add semihosting enable command of the openOCD 25 | * monitor arm semihosting enable 26 | * Add the below function call and prototype to main.c 27 | * extern void initialise_monitor_handles(void); 28 | * initialise_monitor_handles(); 29 | * remove syscalls.c from the project 30 | */ 31 | 32 | initialise_monitor_handles(); 33 | 34 | printf("Hello world\n"); 35 | 36 | for(;;); 37 | } 38 | -------------------------------------------------------------------------------- /Source_code/002_HelloWorld_semihosting/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/003_operation_modes/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | operation_modes 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/003_operation_modes/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/003_operation_modes/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @version V1.0 6 | * @brief Default main function. 7 | ****************************************************************************** 8 | */ 9 | 10 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 11 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 12 | #endif 13 | 14 | #include 15 | #include 16 | 17 | /* This function executes in THREAD MODE of the processor */ 18 | void generate_interrupt() 19 | { 20 | uint32_t *pSTIR = (uint32_t*)0xE000EF00; 21 | uint32_t *pISER0 = (uint32_t*)0xE000E100; 22 | 23 | //enable IRQ3 interrupt 24 | *pISER0 |= ( 1 << 3); 25 | 26 | //generate an interrupt from software for IRQ3 27 | *pSTIR = (3 & 0x1FF); 28 | 29 | } 30 | 31 | /* This function executes in THREAD MODE of the processor */ 32 | int main(void) 33 | { 34 | printf("In thread mode : before interrupt\n"); 35 | 36 | generate_interrupt(); 37 | 38 | printf("In thread mode : after interrupt\n"); 39 | 40 | for(;;); 41 | } 42 | 43 | /* This function(ISR) executes in HANDLER MODE of the processor */ 44 | void RTC_WKUP_IRQHandler(void) 45 | { 46 | printf("In handler mode : ISR\n"); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /Source_code/003_operation_modes/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/004_inline_1/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | inline_1 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/004_inline_1/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/004_inline_1/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @version V1.0 6 | * @brief Default main function. 7 | ****************************************************************************** 8 | */ 9 | 10 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 11 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 12 | #endif 13 | 14 | int main(void) 15 | { 16 | #if 0 17 | __asm volatile("LDR R1,=#0x20001000"); 18 | __asm volatile("LDR R2,=#0x20001004"); 19 | __asm volatile("LDR R0,[R1]"); 20 | __asm volatile("LDR R1,[R2]"); 21 | __asm volatile("ADD R0,R0,R1"); 22 | __asm volatile("STR R0,[R2]"); 23 | #endif 24 | 25 | /* store 'val' in to R0*/ 26 | int val=50; 27 | __asm volatile("MOV R0,%0": :"r"(val)); 28 | 29 | /*read CONTROL register value in to control_reg vriable */ 30 | int control_reg; 31 | __asm volatile("MRS %0,CONTROL": "=r"(control_reg) ); 32 | 33 | 34 | /* Read the value present at pointer p2 in to p1 */ 35 | int p1, *p2; 36 | 37 | p2 = (int*)0x20000008; 38 | 39 | __asm volatile("LDR %0,[%1]": "=r"(p1): "r"(p2)); 40 | 41 | 42 | for(;;); 43 | } 44 | -------------------------------------------------------------------------------- /Source_code/004_inline_1/Src/syscalls.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : syscalls.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | 60 | /* Variables */ 61 | //#undef errno 62 | extern int errno; 63 | extern int __io_putchar(int ch) __attribute__((weak)); 64 | extern int __io_getchar(void) __attribute__((weak)); 65 | 66 | register char * stack_ptr asm("sp"); 67 | 68 | char *__env[1] = { 0 }; 69 | char **environ = __env; 70 | 71 | 72 | /* Functions */ 73 | void initialise_monitor_handles() 74 | { 75 | } 76 | 77 | int _getpid(void) 78 | { 79 | return 1; 80 | } 81 | 82 | int _kill(int pid, int sig) 83 | { 84 | errno = EINVAL; 85 | return -1; 86 | } 87 | 88 | void _exit (int status) 89 | { 90 | _kill(status, -1); 91 | while (1) {} /* Make sure we hang here */ 92 | } 93 | 94 | __attribute__((weak)) int _read(int file, char *ptr, int len) 95 | { 96 | int DataIdx; 97 | 98 | for (DataIdx = 0; DataIdx < len; DataIdx++) 99 | { 100 | *ptr++ = __io_getchar(); 101 | } 102 | 103 | return len; 104 | } 105 | 106 | __attribute__((weak)) int _write(int file, char *ptr, int len) 107 | { 108 | int DataIdx; 109 | 110 | for (DataIdx = 0; DataIdx < len; DataIdx++) 111 | { 112 | __io_putchar(*ptr++); 113 | } 114 | return len; 115 | } 116 | 117 | int _close(int file) 118 | { 119 | return -1; 120 | } 121 | 122 | 123 | int _fstat(int file, struct stat *st) 124 | { 125 | st->st_mode = S_IFCHR; 126 | return 0; 127 | } 128 | 129 | int _isatty(int file) 130 | { 131 | return 1; 132 | } 133 | 134 | int _lseek(int file, int ptr, int dir) 135 | { 136 | return 0; 137 | } 138 | 139 | int _open(char *path, int flags, ...) 140 | { 141 | /* Pretend like we always fail */ 142 | return -1; 143 | } 144 | 145 | int _wait(int *status) 146 | { 147 | errno = ECHILD; 148 | return -1; 149 | } 150 | 151 | int _unlink(char *name) 152 | { 153 | errno = ENOENT; 154 | return -1; 155 | } 156 | 157 | int _times(struct tms *buf) 158 | { 159 | return -1; 160 | } 161 | 162 | int _stat(char *file, struct stat *st) 163 | { 164 | st->st_mode = S_IFCHR; 165 | return 0; 166 | } 167 | 168 | int _link(char *old, char *new) 169 | { 170 | errno = EMLINK; 171 | return -1; 172 | } 173 | 174 | int _fork(void) 175 | { 176 | errno = EAGAIN; 177 | return -1; 178 | } 179 | 180 | int _execve(char *name, char **argv, char **env) 181 | { 182 | errno = ENOMEM; 183 | return -1; 184 | } 185 | -------------------------------------------------------------------------------- /Source_code/004_inline_1/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/005_access_levels/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | access_levels 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/005_access_levels/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/005_access_levels/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @version V1.0 6 | * @brief Default main function. 7 | ****************************************************************************** 8 | */ 9 | 10 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 11 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 12 | #endif 13 | 14 | #include 15 | #include 16 | 17 | /* This function executes in THREAD MODE of the processor */ 18 | void generate_interrupt() 19 | { 20 | uint32_t *pSTIR = (uint32_t*)0xE000EF00; 21 | uint32_t *pISER0 = (uint32_t*)0xE000E100; 22 | 23 | //enable IRQ3 interrupt 24 | *pISER0 |= ( 1 << 3); 25 | 26 | //generate an interrupt from software for IRQ3 27 | *pSTIR = (3 & 0x1FF); 28 | 29 | } 30 | 31 | void change_access_level_unpriv(void) 32 | { 33 | 34 | //read 35 | __asm volatile ("MRS R0,CONTROL"); 36 | //modify 37 | __asm volatile ("ORR R0,R0,#0x01"); 38 | //write 39 | __asm volatile ("MSR CONTROL,R0"); 40 | 41 | } 42 | 43 | /* This function executes in THREAD MODE+ PRIV ACCESS LEVEL of the processor */ 44 | int main(void) 45 | { 46 | printf("In thread mode : before interrupt\n"); 47 | 48 | change_access_level_unpriv(); 49 | 50 | generate_interrupt(); 51 | 52 | printf("In thread mode : after interrupt\n"); 53 | 54 | for(;;); 55 | } 56 | 57 | /* This function(ISR) executes in HANDLER MODE of the processor */ 58 | void RTC_WKUP_IRQHandler(void) 59 | { 60 | printf("In handler mode : ISR\n"); 61 | } 62 | 63 | void HardFault_Handler(void) 64 | { 65 | printf("Hard fault detected\n"); 66 | while(1); 67 | } 68 | -------------------------------------------------------------------------------- /Source_code/005_access_levels/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/006_t-bit/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | t-bit 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/006_t-bit/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/006_t-bit/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @version V1.0 6 | * @brief Default main function. 7 | ****************************************************************************** 8 | */ 9 | 10 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 11 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 12 | #endif 13 | 14 | #include 15 | #include 16 | 17 | /* This function executes in THREAD MODE of the processor */ 18 | void generate_interrupt() 19 | { 20 | uint32_t *pSTIR = (uint32_t*)0xE000EF00; 21 | uint32_t *pISER0 = (uint32_t*)0xE000E100; 22 | 23 | //enable IRQ3 interrupt 24 | *pISER0 |= ( 1 << 3); 25 | 26 | //generate an interrupt from software for IRQ3 27 | *pSTIR = (3 & 0x1FF); 28 | 29 | } 30 | 31 | void change_access_level_unpriv(void) 32 | { 33 | 34 | //read 35 | __asm volatile ("MRS R0,CONTROL"); 36 | //modify 37 | __asm volatile ("ORR R0,R0,#0x01"); 38 | //write 39 | __asm volatile ("MSR CONTROL,R0"); 40 | 41 | } 42 | 43 | /* This function executes in THREAD MODE+ PRIV ACCESS LEVEL of the processor */ 44 | int main(void) 45 | { 46 | printf("In thread mode : before interrupt\n"); 47 | 48 | void (*fun_ptr)(void); 49 | 50 | /* storing some address in the function pointer variable */ 51 | fun_ptr = (void*)0x080001e8; 52 | 53 | /* Here the address 0x080001e8 gets copied into PC 54 | * 0th bit of the address will be copied into T bit. 55 | *Since the 0th bit is 0, T bit becomes 0 which raises processor fault */ 56 | fun_ptr(); 57 | 58 | printf("In thread mode : after interrupt\n"); 59 | 60 | for(;;); 61 | } 62 | 63 | /* This function(ISR) executes in HANDLER MODE of the processor */ 64 | void RTC_WKUP_IRQHandler(void) 65 | { 66 | printf("In handler mode : ISR\n"); 67 | } 68 | 69 | void HardFault_Handler(void) 70 | { 71 | printf("Hard fault detected\n"); 72 | while(1); 73 | } 74 | -------------------------------------------------------------------------------- /Source_code/006_t-bit/Src/syscalls.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : syscalls.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | 60 | /* Variables */ 61 | //#undef errno 62 | extern int errno; 63 | extern int __io_putchar(int ch) __attribute__((weak)); 64 | extern int __io_getchar(void) __attribute__((weak)); 65 | 66 | register char * stack_ptr asm("sp"); 67 | 68 | char *__env[1] = { 0 }; 69 | char **environ = __env; 70 | 71 | 72 | /* Functions */ 73 | void initialise_monitor_handles() 74 | { 75 | } 76 | 77 | int _getpid(void) 78 | { 79 | return 1; 80 | } 81 | 82 | int _kill(int pid, int sig) 83 | { 84 | errno = EINVAL; 85 | return -1; 86 | } 87 | 88 | void _exit (int status) 89 | { 90 | _kill(status, -1); 91 | while (1) {} /* Make sure we hang here */ 92 | } 93 | 94 | __attribute__((weak)) int _read(int file, char *ptr, int len) 95 | { 96 | int DataIdx; 97 | 98 | for (DataIdx = 0; DataIdx < len; DataIdx++) 99 | { 100 | *ptr++ = __io_getchar(); 101 | } 102 | 103 | return len; 104 | } 105 | 106 | __attribute__((weak)) int _write(int file, char *ptr, int len) 107 | { 108 | int DataIdx; 109 | 110 | for (DataIdx = 0; DataIdx < len; DataIdx++) 111 | { 112 | __io_putchar(*ptr++); 113 | } 114 | return len; 115 | } 116 | 117 | int _close(int file) 118 | { 119 | return -1; 120 | } 121 | 122 | 123 | int _fstat(int file, struct stat *st) 124 | { 125 | st->st_mode = S_IFCHR; 126 | return 0; 127 | } 128 | 129 | int _isatty(int file) 130 | { 131 | return 1; 132 | } 133 | 134 | int _lseek(int file, int ptr, int dir) 135 | { 136 | return 0; 137 | } 138 | 139 | int _open(char *path, int flags, ...) 140 | { 141 | /* Pretend like we always fail */ 142 | return -1; 143 | } 144 | 145 | int _wait(int *status) 146 | { 147 | errno = ECHILD; 148 | return -1; 149 | } 150 | 151 | int _unlink(char *name) 152 | { 153 | errno = ENOENT; 154 | return -1; 155 | } 156 | 157 | int _times(struct tms *buf) 158 | { 159 | return -1; 160 | } 161 | 162 | int _stat(char *file, struct stat *st) 163 | { 164 | st->st_mode = S_IFCHR; 165 | return 0; 166 | } 167 | 168 | int _link(char *old, char *new) 169 | { 170 | errno = EMLINK; 171 | return -1; 172 | } 173 | 174 | int _fork(void) 175 | { 176 | errno = EAGAIN; 177 | return -1; 178 | } 179 | 180 | int _execve(char *name, char **argv, char **env) 181 | { 182 | errno = ENOMEM; 183 | return -1; 184 | } 185 | -------------------------------------------------------------------------------- /Source_code/006_t-bit/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/007_bit_banding/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | bit_banding 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/007_bit_banding/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/007_bit_banding/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @version V1.0 6 | * @brief Default main function. 7 | ****************************************************************************** 8 | */ 9 | 10 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 11 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 12 | #endif 13 | 14 | 15 | #include 16 | 17 | #define ALIAS_BASE 0x22000000U 18 | 19 | #define BITBAND_BASE 0x20000000U 20 | 21 | int main(void) 22 | { 23 | uint8_t *ptr = (uint8_t*)0x20000200; 24 | 25 | *ptr = 0xff; 26 | 27 | //normal method 28 | //clearing 7th bit position 29 | *ptr &= ~( 1 << 7); 30 | 31 | //reset to 0xff 32 | *ptr = 0xff; 33 | 34 | //bit band method 35 | uint8_t *alias_addr = (uint8_t*) (ALIAS_BASE+(32 * (0x20000200-BITBAND_BASE))+ 7 * 4); 36 | 37 | //clearing 7th bit of address 0x20000200 38 | *alias_addr = 0; 39 | 40 | for(;;); 41 | } 42 | -------------------------------------------------------------------------------- /Source_code/007_bit_banding/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/008_stack/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | stack 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/008_stack/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/008_stack/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @version V1.0 6 | * @brief Default main function. 7 | ****************************************************************************** 8 | */ 9 | 10 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 11 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 12 | #endif 13 | 14 | #include 15 | 16 | 17 | #define SRAM_START 0x20000000U 18 | #define SRAM_SIZE (128 * 1024) 19 | #define SRAM_END ( (SRAM_START) + (SRAM_SIZE) ) 20 | #define STACK_START SRAM_END 21 | 22 | #define STACK_MSP_START STACK_START 23 | #define STACK_MSP_END (STACK_MSP_START - 512) 24 | #define STACK_PSP_START STACK_MSP_END 25 | 26 | 27 | int fun_add(int a, int b , int c , int d) 28 | { 29 | return a+b+c+d; 30 | } 31 | 32 | 33 | /* this function changes SP to PSP */ 34 | __attribute__((naked)) void change_sp_to_psp(void) 35 | { 36 | __asm volatile(".equ SRAM_END, (0x20000000 + ( 128 * 1024))"); 37 | __asm volatile(".equ PSP_START , (SRAM_END-512)"); 38 | __asm volatile("LDR R0,=PSP_START"); 39 | __asm volatile("MSR PSP, R0"); 40 | __asm volatile("MOV R0,#0X02"); 41 | __asm volatile("MSR CONTROL,R0"); 42 | __asm volatile("BX LR"); 43 | 44 | } 45 | 46 | void generate_exception(void) 47 | { 48 | /* execute SVC instruction to cause SVC exception */ 49 | __asm volatile("SVC #0X2"); 50 | } 51 | 52 | int main(void) 53 | { 54 | change_sp_to_psp(); 55 | 56 | /* from here onwards PSP will be used for stack activities */ 57 | int ret; 58 | 59 | ret = fun_add(1, 4, 5, 6); 60 | 61 | printf("result = %d\n",ret); 62 | 63 | generate_exception(); 64 | 65 | for(;;); 66 | } 67 | 68 | 69 | void SVC_Handler(void) 70 | { 71 | printf(" in SVC_Handler\n"); 72 | } 73 | -------------------------------------------------------------------------------- /Source_code/008_stack/Src/syscalls.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : syscalls.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | 60 | /* Variables */ 61 | //#undef errno 62 | extern int errno; 63 | extern int __io_putchar(int ch) __attribute__((weak)); 64 | extern int __io_getchar(void) __attribute__((weak)); 65 | 66 | register char * stack_ptr asm("sp"); 67 | 68 | char *__env[1] = { 0 }; 69 | char **environ = __env; 70 | 71 | 72 | /* Functions */ 73 | void initialise_monitor_handles() 74 | { 75 | } 76 | 77 | int _getpid(void) 78 | { 79 | return 1; 80 | } 81 | 82 | int _kill(int pid, int sig) 83 | { 84 | errno = EINVAL; 85 | return -1; 86 | } 87 | 88 | void _exit (int status) 89 | { 90 | _kill(status, -1); 91 | while (1) {} /* Make sure we hang here */ 92 | } 93 | 94 | __attribute__((weak)) int _read(int file, char *ptr, int len) 95 | { 96 | int DataIdx; 97 | 98 | for (DataIdx = 0; DataIdx < len; DataIdx++) 99 | { 100 | *ptr++ = __io_getchar(); 101 | } 102 | 103 | return len; 104 | } 105 | 106 | __attribute__((weak)) int _write(int file, char *ptr, int len) 107 | { 108 | int DataIdx; 109 | 110 | for (DataIdx = 0; DataIdx < len; DataIdx++) 111 | { 112 | __io_putchar(*ptr++); 113 | } 114 | return len; 115 | } 116 | 117 | int _close(int file) 118 | { 119 | return -1; 120 | } 121 | 122 | 123 | int _fstat(int file, struct stat *st) 124 | { 125 | st->st_mode = S_IFCHR; 126 | return 0; 127 | } 128 | 129 | int _isatty(int file) 130 | { 131 | return 1; 132 | } 133 | 134 | int _lseek(int file, int ptr, int dir) 135 | { 136 | return 0; 137 | } 138 | 139 | int _open(char *path, int flags, ...) 140 | { 141 | /* Pretend like we always fail */ 142 | return -1; 143 | } 144 | 145 | int _wait(int *status) 146 | { 147 | errno = ECHILD; 148 | return -1; 149 | } 150 | 151 | int _unlink(char *name) 152 | { 153 | errno = ENOENT; 154 | return -1; 155 | } 156 | 157 | int _times(struct tms *buf) 158 | { 159 | return -1; 160 | } 161 | 162 | int _stat(char *file, struct stat *st) 163 | { 164 | st->st_mode = S_IFCHR; 165 | return 0; 166 | } 167 | 168 | int _link(char *old, char *new) 169 | { 170 | errno = EMLINK; 171 | return -1; 172 | } 173 | 174 | int _fork(void) 175 | { 176 | errno = EAGAIN; 177 | return -1; 178 | } 179 | 180 | int _execve(char *name, char **argv, char **env) 181 | { 182 | errno = ENOMEM; 183 | return -1; 184 | } 185 | -------------------------------------------------------------------------------- /Source_code/008_stack/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/009_USART3_int_pend/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | USART3_int_pend 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/009_USART3_int_pend/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/009_USART3_int_pend/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @version V1.0 6 | * @brief Default main function. 7 | ****************************************************************************** 8 | */ 9 | 10 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 11 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 12 | #endif 13 | 14 | #include 15 | #include 16 | 17 | #define USART3_IRQNO 39 18 | 19 | int main(void) 20 | { 21 | //1. Manually pend the pending bit for the USART3 IRQ number in NVIC 22 | uint32_t *pISPR1 = (uint32_t*)0XE000E204; 23 | *pISPR1 |= ( 1 << (USART3_IRQNO % 32)); 24 | 25 | //2. Enable the USART3 IRQ number in NVIC 26 | uint32_t *pISER1 = (uint32_t*)0xE000E104; 27 | *pISER1 |= ( 1 << (USART3_IRQNO % 32)); 28 | 29 | for(;;); 30 | } 31 | 32 | //USART3 ISR 33 | void USART3_IRQHandler(void) 34 | { 35 | printf("in USART3 isr\n"); 36 | } 37 | -------------------------------------------------------------------------------- /Source_code/009_USART3_int_pend/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/010_interrupt_priority/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | interrupt_priority 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/010_interrupt_priority/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/010_interrupt_priority/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @version V1.0 6 | * @brief Default main function. 7 | ****************************************************************************** 8 | */ 9 | 10 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 11 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 12 | #endif 13 | 14 | #define IRQNO_TIMER2 28 15 | #define IRQNO_I2C1 31 16 | 17 | #include 18 | #include 19 | 20 | /* NVIC register addresses. Refer to the processor generic guide */ 21 | uint32_t *pNVIC_IPRBase = (uint32_t*)0xE000E400; 22 | uint32_t *pNVIC_ISERBase = (uint32_t*)0xE000E100; 23 | uint32_t *pNVIC_ISPRBase = (uint32_t*)0XE000E200; 24 | 25 | 26 | void configure_priority_for_irqs(uint8_t irq_no, uint8_t priority_value) 27 | { 28 | //1. find out iprx 29 | uint8_t iprx = irq_no / 4; 30 | uint32_t *ipr = pNVIC_IPRBase+iprx; 31 | 32 | //2. position in iprx 33 | uint8_t pos = (irq_no % 4) * 8; 34 | 35 | //3. configure the priority 36 | *ipr &= ~(0xFF << pos);//clear 37 | *ipr |= (priority_value << pos); 38 | 39 | } 40 | 41 | int main(void) 42 | { 43 | //1. Lets configure the priority for the peripherals 44 | configure_priority_for_irqs(IRQNO_TIMER2,0x80); 45 | configure_priority_for_irqs(IRQNO_I2C1,0x70); 46 | 47 | //2. Set the interrupt pending bit in the NVIC PR 48 | *pNVIC_ISPRBase |= ( 1 << IRQNO_TIMER2); 49 | 50 | //3. Enable the IRQs in NVIC ISER 51 | *pNVIC_ISERBase |= ( 1 << IRQNO_I2C1); 52 | *pNVIC_ISERBase |= ( 1 << IRQNO_TIMER2); 53 | 54 | 55 | } 56 | 57 | //isrs 58 | 59 | void TIM2_IRQHandler(void) 60 | { 61 | printf("[TIM2_IRQHandler]\n"); 62 | /*Here, we are pending I2C interrupt request manually */ 63 | *pNVIC_ISPRBase |= ( 1 << IRQNO_I2C1); 64 | while(1); 65 | 66 | } 67 | 68 | 69 | void I2C1_EV_IRQHandler(void) 70 | { 71 | printf("[I2C1_EV_IRQHandler]\n"); 72 | } 73 | -------------------------------------------------------------------------------- /Source_code/010_interrupt_priority/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/011_exception_entry_exit/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | exception_entry_exit 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/011_exception_entry_exit/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/011_exception_entry_exit/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @version V1.0 6 | * @brief Default main function. 7 | ****************************************************************************** 8 | */ 9 | 10 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 11 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 12 | #endif 13 | 14 | #include 15 | #include 16 | 17 | /* This function executes in THREAD MODE of the processor */ 18 | void generate_interrupt() 19 | { 20 | uint32_t *pSTIR = (uint32_t*)0xE000EF00; 21 | uint32_t *pISER0 = (uint32_t*)0xE000E100; 22 | 23 | //enable IRQ3 interrupt 24 | *pISER0 |= ( 1 << 3); 25 | 26 | //generate an interrupt from software for IRQ3 27 | *pSTIR = (3 & 0x1FF); 28 | 29 | } 30 | 31 | /* This function executes in THREAD MODE of the processor */ 32 | int main(void) 33 | { 34 | int control_reg = 0x2; 35 | uint32_t psp_value = 0x20008000; 36 | 37 | /* this code modifies the CONTROL register for SP selection */ 38 | __asm volatile ("msr PSP,%0"::"r"(psp_value)); 39 | __asm volatile ("msr CONTROL,%0"::"r"(control_reg)); 40 | 41 | printf("In thread mode : before interrupt\n"); 42 | 43 | generate_interrupt(); 44 | 45 | printf("In thread mode : after interrupt\n"); 46 | 47 | for(;;); 48 | } 49 | 50 | /* This function(ISR) executes in HANDLER MODE of the processor */ 51 | void RTC_WKUP_IRQHandler(void) 52 | { 53 | printf("In handler mode : ISR\n"); 54 | } 55 | 56 | -------------------------------------------------------------------------------- /Source_code/011_exception_entry_exit/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/012_fault_gen/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fault_gen 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/012_fault_gen/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/012_fault_gen/Src/main-1.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | ****************************************************************************** 4 | * @file main.c 5 | * @author Auto-generated by STM32CubeIDE 6 | * @version V1.0 7 | * @brief Default main function. 8 | ****************************************************************************** 9 | */ 10 | 11 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 12 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 13 | #endif 14 | 15 | #include 16 | #include 17 | 18 | void UsageFault_Handler_c(uint32_t *pMSP); 19 | 20 | int fun_divide(int x , int y) 21 | { 22 | 23 | return x/y; 24 | } 25 | 26 | int main(void) 27 | { 28 | //1. enable all configurable exceptions like usage fault, mem manage fault and bus fault 29 | 30 | uint32_t *pSHCSR = (uint32_t*)0xE000ED24; 31 | 32 | *pSHCSR |= ( 1 << 16); //mem manage 33 | *pSHCSR |= ( 1 << 17); //bus fault 34 | //*pSHCSR |= ( 1 << 18); //usage fault 35 | 36 | //2. enable divide by zero trap 37 | uint32_t *pCCR = (uint32_t*)0xE000ED14; 38 | *pCCR |= ( 1 << 4); 39 | 40 | //3. attempt to divide by zero 41 | fun_divide(10,0); 42 | 43 | for(;;); 44 | } 45 | 46 | //2. implement the fault handlers 47 | void HardFault_Handler(void) 48 | { 49 | printf("Exception : Hardfault\n"); 50 | while(1); 51 | } 52 | 53 | 54 | void MemManage_Handler(void) 55 | { 56 | printf("Exception : MemManage\n"); 57 | while(1); 58 | } 59 | 60 | void BusFault_Handler(void) 61 | { 62 | printf("Exception : BusFault\n"); 63 | while(1); 64 | } 65 | 66 | 67 | __attribute__ ((naked)) void UsageFault_Handler(void) 68 | { 69 | //here we extracted the value of MSP which happens to be the 70 | //base address of the stack frame(thread mode) which got saved during the exception entry 71 | //from thread mode to handler mode 72 | __asm ("MRS r0,MSP"); 73 | __asm ("B UsageFault_Handler_c"); 74 | } 75 | 76 | void UsageFault_Handler_c(uint32_t *pBaseStackFrame) 77 | { 78 | uint32_t *pUFSR = (uint32_t*)0xE000ED2A; 79 | printf("Exception : UsageFault\n"); 80 | printf("UFSR = %lx\n",(*pUFSR) & 0xFFFF); 81 | printf("pBaseStackFrame = %p\n",pBaseStackFrame); 82 | printf("Value of R0 = %lx\n", pBaseStackFrame[0]); 83 | printf("Value of R1 = %lx\n", pBaseStackFrame[1]); 84 | printf("Value of R2 = %lx\n", pBaseStackFrame[2]); 85 | printf("Value of R3 = %lx\n", pBaseStackFrame[3]); 86 | printf("Value of R12 = %lx\n", pBaseStackFrame[4]); 87 | printf("Value of LR = %lx\n", pBaseStackFrame[5]); 88 | printf("Value of PC = %lx\n", pBaseStackFrame[6]); 89 | printf("Value of XPSR = %lx\n", pBaseStackFrame[7]); 90 | while(1); 91 | } 92 | 93 | -------------------------------------------------------------------------------- /Source_code/012_fault_gen/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @version V1.0 6 | * @brief Default main function. 7 | ****************************************************************************** 8 | */ 9 | 10 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 11 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 12 | #endif 13 | 14 | #include 15 | #include 16 | 17 | void UsageFault_Handler_c(uint32_t *pMSP); 18 | 19 | int main(void) 20 | { 21 | //1. enable all configurable exceptions : usage fault, mem manage fault and bus fault 22 | 23 | uint32_t *pSHCSR = (uint32_t*)0xE000ED24; 24 | 25 | *pSHCSR |= ( 1 << 16); //mem manage 26 | *pSHCSR |= ( 1 << 17); //bus fault 27 | *pSHCSR |= ( 1 << 18); //usage fault 28 | 29 | 30 | //3. lets force the processor to execute some undefined instruction 31 | uint32_t *pSRAM = (uint32_t*)0x20010000; 32 | 33 | /*This is an undefined instruction value */ 34 | *pSRAM = 0xFFFFFFFF; 35 | 36 | /* This is a function pointer variable */ 37 | void (*some_address) (void); 38 | 39 | /* initialize the function pointer variable to some address */ 40 | some_address = (void*)0x20010001; 41 | 42 | /* change PC to jump to location 0x20010000 */ 43 | some_address(); 44 | 45 | //4. analyze the fault 46 | 47 | for(;;); 48 | } 49 | 50 | //2. implement the fault handlers 51 | void HardFault_Handler(void) 52 | { 53 | printf("Exception : Hardfault\n"); 54 | while(1); 55 | } 56 | 57 | 58 | void MemManage_Handler(void) 59 | { 60 | printf("Exception : MemManage\n"); 61 | while(1); 62 | } 63 | 64 | void BusFault_Handler(void) 65 | { 66 | printf("Exception : BusFault\n"); 67 | while(1); 68 | } 69 | 70 | 71 | __attribute__ ((naked)) void UsageFault_Handler(void) 72 | { 73 | //here we extracted the value of MSP which happens to be the 74 | //base address of the stack frame(thread mode) which got saved during the exception entry 75 | //from thread mode to handler mode 76 | __asm ("MRS r0,MSP"); 77 | __asm ("B UsageFault_Handler_c"); 78 | } 79 | 80 | void UsageFault_Handler_c(uint32_t *pBaseStackFrame) 81 | { 82 | uint32_t *pUFSR = (uint32_t*)0xE000ED2A; 83 | printf("Exception : UsageFault\n"); 84 | printf("UFSR = %lx\n",(*pUFSR) & 0xFFFF); 85 | printf("pBaseStackFrame = %p\n",pBaseStackFrame); 86 | printf("Value of R0 = %lx\n", pBaseStackFrame[0]); 87 | printf("Value of R1 = %lx\n", pBaseStackFrame[1]); 88 | printf("Value of R2 = %lx\n", pBaseStackFrame[2]); 89 | printf("Value of R3 = %lx\n", pBaseStackFrame[3]); 90 | printf("Value of R12 = %lx\n", pBaseStackFrame[4]); 91 | printf("Value of LR = %lx\n", pBaseStackFrame[5]); 92 | printf("Value of PC = %lx\n", pBaseStackFrame[6]); 93 | printf("Value of XPSR = %lx\n", pBaseStackFrame[7]); 94 | while(1); 95 | } 96 | 97 | -------------------------------------------------------------------------------- /Source_code/012_fault_gen/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/013_svc_number/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | svc_number 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/013_svc_number/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/013_svc_number/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @version V1.0 6 | * @brief Default main function. 7 | ****************************************************************************** 8 | */ 9 | 10 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 11 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 12 | #endif 13 | 14 | /* 15 | Write a program to execute an SVC instruction from thread mode, 16 | implement the svc handler to print the SVC number used. 17 | Also, increment the SVC number by 4 and return it to the thread mode code and print it. 18 | Hints : 19 | 1)Write a main() function where you should execute the SVC instruction with an argument. 20 | let's say SVC #0x5 21 | 2)Implement the SVC handler 22 | 3)In the SVC handler extract the SVC number and print it using printf 23 | 4) Increment the SVC number by 4 and return it to the thread mode 24 | */ 25 | 26 | #include 27 | #include 28 | int main(void) 29 | { 30 | __asm volatile ("SVC #25"); 31 | 32 | //register uint32_t data __asm("r0"); 33 | 34 | uint32_t data; 35 | 36 | __asm volatile ("MOV %0,R0": "=r"(data) ::); 37 | 38 | printf(" data = %ld\n",data); 39 | 40 | for(;;); 41 | } 42 | 43 | 44 | __attribute__ ((naked)) void SVC_Handler(void) 45 | { 46 | //1 . get the value of the MSP 47 | __asm("MRS R0,MSP"); 48 | __asm("B SVC_Handler_c"); 49 | } 50 | 51 | void SVC_Handler_c(uint32_t *pBaseOfStackFrame) 52 | { 53 | printf("in SVC handler\n"); 54 | 55 | uint8_t *pReturn_addr = (uint8_t*)pBaseOfStackFrame[6]; 56 | 57 | //2. decrement the return address by 2 to point to 58 | //opcode of the SVC instruction in the program memory 59 | pReturn_addr-=2; 60 | 61 | 62 | //3. extract the SVC number (LSByte of the opcode) 63 | uint8_t svc_number = *pReturn_addr; 64 | 65 | printf("Svc number is : %d\n",svc_number); 66 | 67 | svc_number+=4; 68 | 69 | pBaseOfStackFrame[0] = svc_number; 70 | 71 | } 72 | -------------------------------------------------------------------------------- /Source_code/013_svc_number/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/013_svc_number/svc_number Debug.cfg: -------------------------------------------------------------------------------- 1 | # This is an STM32F407G-DISC1 board with a single STM32F407VGTx chip 2 | # 3 | # Generated by STM32CubeIDE 4 | # Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s) 5 | 6 | source [find interface/stlink.cfg] 7 | 8 | set WORKAREASIZE 0x8000 9 | 10 | transport select "hla_swd" 11 | 12 | set CHIPNAME STM32F407VGTx 13 | set BOARDNAME STM32F407G-DISC1 14 | 15 | # Enable debug when in low power modes 16 | set ENABLE_LOW_POWER 1 17 | 18 | # Stop Watchdog counters when halt 19 | set STOP_WATCHDOG 1 20 | 21 | # STlink Debug clock frequency 22 | set CLOCK_FREQ 8000 23 | 24 | # Reset configuration 25 | # use hardware reset, connect under reset 26 | # connect_assert_srst needed if low power mode application running (WFI...) 27 | reset_config srst_only srst_nogate connect_assert_srst 28 | set CONNECT_UNDER_RESET 1 29 | set CORE_RESET 0 30 | 31 | 32 | 33 | # BCTM CPU variables 34 | 35 | 36 | 37 | source [find target/stm32f4x.cfg] 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Source_code/014_svc_operation/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | svc_operation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/014_svc_operation/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/014_svc_operation/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @version V1.0 6 | * @brief Default main function. 7 | ****************************************************************************** 8 | */ 9 | 10 | #if !defined(__SOFT_FP__) && defined(__ARM_FP) 11 | #warning "FPU is not initialized, but the project is compiling for an FPU. Please initialize the FPU before use." 12 | #endif 13 | 14 | #include 15 | #include 16 | 17 | void SVC_Handle_c(uint32_t *pBaseStackFrame); 18 | 19 | int32_t add_numbers(int32_t x , int32_t y ) 20 | { 21 | int32_t res; 22 | __asm volatile("SVC #36"); 23 | __asm volatile ("MOV %0,R0": "=r"(res) ::); 24 | return res; 25 | 26 | } 27 | 28 | 29 | int32_t sub_numbers(int32_t x , int32_t y ) 30 | { 31 | int32_t res; 32 | __asm volatile("SVC #37"); 33 | __asm volatile ("MOV %0,R0": "=r"(res) ::); 34 | return res; 35 | 36 | 37 | } 38 | 39 | int32_t mul_numbers(int32_t x , int32_t y ) 40 | { 41 | int32_t res; 42 | __asm volatile("SVC #38"); 43 | __asm volatile ("MOV %0,R0": "=r"(res) ::); 44 | return res; 45 | 46 | 47 | } 48 | 49 | int32_t div_numbers(int32_t x , int32_t y ) 50 | { 51 | int32_t res; 52 | __asm volatile("SVC #39"); 53 | __asm volatile ("MOV %0,R0": "=r"(res) ::); 54 | return res; 55 | 56 | } 57 | 58 | 59 | int main(void) 60 | { 61 | int32_t res; 62 | 63 | res = add_numbers(40, -90); 64 | printf("Add result = %ld\n",res); 65 | 66 | res = sub_numbers(25,150); 67 | printf("Sub result = %ld\n",res); 68 | 69 | res = mul_numbers(374,890); 70 | printf("mul result = %ld\n", res); 71 | 72 | res = div_numbers(67,-3); 73 | printf("div result = %ld\n",res); 74 | 75 | 76 | 77 | for(;;); 78 | } 79 | 80 | 81 | __attribute__( ( naked ) ) void SVC_Handler( void ) 82 | { 83 | __asm ("MRS r0,MSP"); 84 | __asm( "B SVC_Handler_c"); 85 | } 86 | 87 | 88 | void SVC_Handler_c(uint32_t *pBaseOfStackFrame) 89 | { 90 | printf("in SVC handler\n"); 91 | 92 | int32_t arg0, arg1,res; 93 | 94 | uint8_t *pReturn_addr = (uint8_t*)pBaseOfStackFrame[6]; 95 | 96 | //2. decrement the return address by 2 to point to 97 | //opcode of the SVC instruction in the program memory 98 | pReturn_addr-=2; 99 | 100 | 101 | //3. extract the SVC number (LSByte of the opcode) 102 | uint8_t svc_number = *pReturn_addr; 103 | 104 | printf("Svc number is : %d\n",svc_number); 105 | 106 | /* get the operands for the operation */ 107 | arg0 = pBaseOfStackFrame[0]; 108 | arg1 = pBaseOfStackFrame[1]; 109 | 110 | /*SVC number signifies the type of operation , decode it */ 111 | switch(svc_number) 112 | { 113 | case 36: 114 | res = arg0 + arg1; 115 | break; 116 | case 37: 117 | res = arg0 - arg1; 118 | break; 119 | case 38: 120 | res = arg0 * arg1; 121 | break; 122 | case 39: 123 | res = arg0/arg1; 124 | break; 125 | default: 126 | printf("invalid svc code\n"); 127 | 128 | } 129 | 130 | /*store the result back to stack frame at R0's position */ 131 | pBaseOfStackFrame[0] = res; 132 | 133 | } 134 | -------------------------------------------------------------------------------- /Source_code/014_svc_operation/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/015_task_scheduler/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | task_scheduler 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/015_task_scheduler/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/015_task_scheduler/Inc/led.h: -------------------------------------------------------------------------------- 1 | /* 2 | * led.h 3 | * 4 | * Created on: 28-Dec-2019 5 | * Author: nieki 6 | */ 7 | 8 | #ifndef LED_H_ 9 | #define LED_H_ 10 | 11 | #define LED_GREEN 12 12 | #define LED_ORANGE 13 13 | #define LED_RED 14 14 | #define LED_BLUE 15 15 | 16 | #define DELAY_COUNT_1MS 1250U 17 | #define DELAY_COUNT_1S (1000U * DELAY_COUNT_1MS) 18 | #define DELAY_COUNT_500MS (500U * DELAY_COUNT_1MS) 19 | #define DELAY_COUNT_250MS (250U * DELAY_COUNT_1MS) 20 | #define DELAY_COUNT_125MS (125U * DELAY_COUNT_1MS) 21 | 22 | void led_init_all(void); 23 | void led_on(uint8_t led_no); 24 | void led_off(uint8_t led_no); 25 | void delay(uint32_t count); 26 | 27 | #endif /* LED_H_ */ 28 | -------------------------------------------------------------------------------- /Source_code/015_task_scheduler/Inc/main.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef MAIN_H_ 3 | #define MAIN_H_ 4 | 5 | 6 | #define MAX_TASKS 5 7 | 8 | /* some stack memory calculations */ 9 | #define SIZE_TASK_STACK 1024U 10 | #define SIZE_SCHED_STACK 1024U 11 | 12 | #define SRAM_START 0x20000000U 13 | #define SIZE_SRAM ( (128) * (1024)) 14 | #define SRAM_END ((SRAM_START) + (SIZE_SRAM) ) 15 | 16 | #define T1_STACK_START SRAM_END 17 | #define T2_STACK_START ( (SRAM_END) - (1 * SIZE_TASK_STACK) ) 18 | #define T3_STACK_START ( (SRAM_END) - (2 * SIZE_TASK_STACK) ) 19 | #define T4_STACK_START ( (SRAM_END) - (3 * SIZE_TASK_STACK) ) 20 | #define IDLE_STACK_START ( (SRAM_END) - (4 * SIZE_TASK_STACK) ) 21 | #define SCHED_STACK_START ( (SRAM_END) - (5 * SIZE_TASK_STACK) ) 22 | 23 | #define TICK_HZ 1000U 24 | 25 | #define HSI_CLOCK 16000000U 26 | #define SYSTICK_TIM_CLK HSI_CLOCK 27 | 28 | 29 | #define DUMMY_XPSR 0x01000000U 30 | 31 | #define TASK_READY_STATE 0x00 32 | #define TASK_BLOCKED_STATE 0XFF 33 | 34 | #define INTERRUPT_DISABLE() do{__asm volatile ("MOV R0,#0x1"); asm volatile("MSR PRIMASK,R0"); } while(0) 35 | 36 | #define INTERRUPT_ENABLE() do{__asm volatile ("MOV R0,#0x0"); asm volatile("MSR PRIMASK,R0"); } while(0) 37 | 38 | #endif /* MAIN_H_ */ 39 | -------------------------------------------------------------------------------- /Source_code/015_task_scheduler/Src/led.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "led.h" 4 | 5 | 6 | 7 | void delay(uint32_t count) 8 | { 9 | for(uint32_t i = 0 ; i < count ; i++); 10 | } 11 | 12 | void led_init_all(void) 13 | { 14 | 15 | uint32_t *pRccAhb1enr = (uint32_t*)0x40023830; 16 | uint32_t *pGpiodModeReg = (uint32_t*)0x40020C00; 17 | 18 | 19 | *pRccAhb1enr |= ( 1 << 3); 20 | //configure LED_GREEN 21 | *pGpiodModeReg |= ( 1 << (2 * LED_GREEN)); 22 | *pGpiodModeReg |= ( 1 << (2 * LED_ORANGE)); 23 | *pGpiodModeReg |= ( 1 << (2 * LED_RED)); 24 | *pGpiodModeReg |= ( 1 << (2 * LED_BLUE)); 25 | 26 | #if 0 27 | //configure the outputtype 28 | *pGpioOpTypeReg |= ( 1 << (2 * LED_GREEN)); 29 | *pGpioOpTypeReg |= ( 1 << (2 * LED_ORANGE)); 30 | *pGpioOpTypeReg |= ( 1 << (2 * LED_RED)); 31 | *pGpioOpTypeReg |= ( 1 << (2 * LED_BLUE)); 32 | #endif 33 | 34 | led_off(LED_GREEN); 35 | led_off(LED_ORANGE); 36 | led_off(LED_RED); 37 | led_off(LED_BLUE); 38 | 39 | 40 | 41 | } 42 | 43 | void led_on(uint8_t led_no) 44 | { 45 | uint32_t *pGpiodDataReg = (uint32_t*)0x40020C14; 46 | *pGpiodDataReg |= ( 1 << led_no); 47 | 48 | } 49 | 50 | void led_off(uint8_t led_no) 51 | { 52 | uint32_t *pGpiodDataReg = (uint32_t*)0x40020C14; 53 | *pGpiodDataReg &= ~( 1 << led_no); 54 | 55 | } 56 | 57 | 58 | -------------------------------------------------------------------------------- /Source_code/015_task_scheduler/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/016_cmsis_task_scheduler/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | cmsis_task_scheduler 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | org.eclipse.cdt.core.cnature 24 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature 25 | com.st.stm32cube.ide.mcu.MCUManagedMakefileProjectNature 26 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 27 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 28 | com.st.stm32cube.ide.mcu.MCURootProjectNature 29 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 30 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 31 | 32 | 33 | -------------------------------------------------------------------------------- /Source_code/016_cmsis_task_scheduler/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Source_code/016_cmsis_task_scheduler/Inc/led.h: -------------------------------------------------------------------------------- 1 | /* 2 | * led.h 3 | * 4 | * Created on: 28-Dec-2019 5 | * Author: nieki 6 | */ 7 | 8 | #ifndef LED_H_ 9 | #define LED_H_ 10 | 11 | #define LED_GREEN 12 12 | #define LED_ORANGE 13 13 | #define LED_RED 14 14 | #define LED_BLUE 15 15 | 16 | #define DELAY_COUNT_1MS 1250U 17 | #define DELAY_COUNT_1S (1000U * DELAY_COUNT_1MS) 18 | #define DELAY_COUNT_500MS (500U * DELAY_COUNT_1MS) 19 | #define DELAY_COUNT_250MS (250U * DELAY_COUNT_1MS) 20 | #define DELAY_COUNT_125MS (125U * DELAY_COUNT_1MS) 21 | 22 | void led_init_all(void); 23 | void led_on(uint8_t led_no); 24 | void led_off(uint8_t led_no); 25 | void delay(uint32_t count); 26 | 27 | #endif /* LED_H_ */ 28 | -------------------------------------------------------------------------------- /Source_code/016_cmsis_task_scheduler/Inc/main.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef MAIN_H_ 3 | #define MAIN_H_ 4 | 5 | 6 | #define MAX_TASKS 5 7 | 8 | /* some stack memory calculations */ 9 | #define SIZE_TASK_STACK 1024U 10 | #define SIZE_SCHED_STACK 1024U 11 | 12 | #define SRAM_START 0x20000000U 13 | #define SIZE_SRAM ( (128) * (1024)) 14 | #define SRAM_END ((SRAM_START) + (SIZE_SRAM) ) 15 | 16 | #define T1_STACK_START SRAM_END 17 | #define T2_STACK_START ( (SRAM_END) - (1 * SIZE_TASK_STACK) ) 18 | #define T3_STACK_START ( (SRAM_END) - (2 * SIZE_TASK_STACK) ) 19 | #define T4_STACK_START ( (SRAM_END) - (3 * SIZE_TASK_STACK) ) 20 | #define IDLE_STACK_START ( (SRAM_END) - (4 * SIZE_TASK_STACK) ) 21 | #define SCHED_STACK_START ( (SRAM_END) - (5 * SIZE_TASK_STACK) ) 22 | 23 | #define TICK_HZ 1000U 24 | 25 | #define HSI_CLOCK 16000000U 26 | #define SYSTICK_TIM_CLK HSI_CLOCK 27 | 28 | 29 | #define DUMMY_XPSR 0x01000000U 30 | 31 | #define TASK_READY_STATE 0x00 32 | #define TASK_BLOCKED_STATE 0XFF 33 | 34 | #define INTERRUPT_DISABLE() do{__asm volatile ("MOV R0,#0x1"); asm volatile("MSR PRIMASK,R0"); } while(0) 35 | 36 | #define INTERRUPT_ENABLE() do{__asm volatile ("MOV R0,#0x0"); asm volatile("MSR PRIMASK,R0"); } while(0) 37 | 38 | #endif /* MAIN_H_ */ 39 | -------------------------------------------------------------------------------- /Source_code/016_cmsis_task_scheduler/Src/led.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "led.h" 4 | 5 | 6 | 7 | void delay(uint32_t count) 8 | { 9 | for(uint32_t i = 0 ; i < count ; i++); 10 | } 11 | 12 | void led_init_all(void) 13 | { 14 | 15 | uint32_t *pRccAhb1enr = (uint32_t*)0x40023830; 16 | uint32_t *pGpiodModeReg = (uint32_t*)0x40020C00; 17 | 18 | 19 | *pRccAhb1enr |= ( 1 << 3); 20 | //configure LED_GREEN 21 | *pGpiodModeReg |= ( 1 << (2 * LED_GREEN)); 22 | *pGpiodModeReg |= ( 1 << (2 * LED_ORANGE)); 23 | *pGpiodModeReg |= ( 1 << (2 * LED_RED)); 24 | *pGpiodModeReg |= ( 1 << (2 * LED_BLUE)); 25 | 26 | #if 0 27 | //configure the outputtype 28 | *pGpioOpTypeReg |= ( 1 << (2 * LED_GREEN)); 29 | *pGpioOpTypeReg |= ( 1 << (2 * LED_ORANGE)); 30 | *pGpioOpTypeReg |= ( 1 << (2 * LED_RED)); 31 | *pGpioOpTypeReg |= ( 1 << (2 * LED_BLUE)); 32 | #endif 33 | 34 | led_off(LED_GREEN); 35 | led_off(LED_ORANGE); 36 | led_off(LED_RED); 37 | led_off(LED_BLUE); 38 | 39 | 40 | 41 | } 42 | 43 | void led_on(uint8_t led_no) 44 | { 45 | uint32_t *pGpiodDataReg = (uint32_t*)0x40020C14; 46 | *pGpiodDataReg |= ( 1 << led_no); 47 | 48 | } 49 | 50 | void led_off(uint8_t led_no) 51 | { 52 | uint32_t *pGpiodDataReg = (uint32_t*)0x40020C14; 53 | *pGpiodDataReg &= ~( 1 << led_no); 54 | 55 | } 56 | 57 | 58 | -------------------------------------------------------------------------------- /Source_code/016_cmsis_task_scheduler/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : sysmem.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | 53 | /* Variables */ 54 | extern int errno; 55 | register char * stack_ptr asm("sp"); 56 | 57 | /* Functions */ 58 | 59 | /** 60 | _sbrk 61 | Increase program data space. Malloc and related functions depend on this 62 | **/ 63 | caddr_t _sbrk(int incr) 64 | { 65 | extern char end asm("end"); 66 | static char *heap_end; 67 | char *prev_heap_end; 68 | 69 | if (heap_end == 0) 70 | heap_end = &end; 71 | 72 | prev_heap_end = heap_end; 73 | if (heap_end + incr > stack_ptr) 74 | { 75 | errno = ENOMEM; 76 | return (caddr_t) -1; 77 | } 78 | 79 | heap_end += incr; 80 | 81 | return (caddr_t) prev_heap_end; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /Source_code/016_cmsis_task_scheduler/driver/CMSIS/Core/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.3 5 | * @date 24. June 2019 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2019 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 3U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /Source_code/016_cmsis_task_scheduler/driver/CMSIS/Core/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /Source_code/016_cmsis_task_scheduler/driver/Device/ST/ReadMe.txt: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * @file ReadMe.txt 3 | * @brief Explanation how to use the Device folder and template files 4 | * @version V3.0.3 5 | * @date 10. January 2018 6 | *****************************************************************************/ 7 | 8 | Following directory structure and template files are given: 9 | 10 | - 11 | | 12 | +-- 13 | | 14 | +-- Include 15 | | +- .h header file 16 | | +- system_Device.h system include file 17 | +-- Source 18 | | 19 | +- system_.c system source file 20 | | 21 | +-- ARM Arm RVCT toolchain 22 | | +- startup_.s ASM startup file for ARMCC 23 | | 24 | +-- GCC Arm GNU toolchain 25 | | 26 | +-- IAR IAR toolchain 27 | 28 | 29 | Copy the complete folder including files and replace: 30 | - folder name 'Vendor' with the abbreviation for the device vendor e.g.: NXP. 31 | - folder name 'Device' with your specific device name e.g.: LPC17xx. 32 | - in the filenames 'Device' with your specific device name e.g.: LPC17xx. 33 | 34 | 35 | The template files contain comments starting with 'ToDo: ' 36 | There it is described what you need to do. 37 | 38 | 39 | The template files contain following placeholder: 40 | 41 | 42 | should be replaced with your specific device name. 43 | e.g.: LPC17xx 44 | 45 | 46 | should be replaced with a specific device interrupt name. 47 | e.g.: TIM1 for Timer#1 interrupt. 48 | 49 | 50 | should be replaced with a dedicated device family 51 | abbreviation (e.g.: LPC for LPC17xx device family) 52 | 53 | Cortex-M# 54 | Cortex-M# can be replaced with the specific Cortex-M number 55 | e.g.: Cortex-M3 56 | 57 | 58 | 59 | Note: 60 | Template files (i.e. startup_Device.s, system_Device.c) are application 61 | specific and therefore expected to be copied into the application project 62 | folder prior to use! 63 | -------------------------------------------------------------------------------- /Source_code/016_cmsis_task_scheduler/driver/Device/ST/ST/stm32f4xx/Include/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file system_stm32f4xx.h 3 | * @brief CMSIS Cortex-M# Device Peripheral Access Layer Header File for 4 | * Device stm32f4xx 5 | * @version V5.00 6 | * @date 10. January 2018 7 | ******************************************************************************/ 8 | /* 9 | * Copyright (c) 2009-2018 Arm Limited. All rights reserved. 10 | * 11 | * SPDX-License-Identifier: Apache-2.0 12 | * 13 | * Licensed under the Apache License, Version 2.0 (the License); you may 14 | * not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 21 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | */ 25 | 26 | #ifndef SYSTEM_stm32f4xx_H /* ToDo: replace 'stm32f4xx' with your device name */ 27 | #define SYSTEM_stm32f4xx_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #include 34 | 35 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 36 | 37 | 38 | /** 39 | \brief Setup the microcontroller system. 40 | 41 | Initialize the System and update the SystemCoreClock variable. 42 | */ 43 | extern void SystemInit (void); 44 | 45 | 46 | /** 47 | \brief Update SystemCoreClock variable. 48 | 49 | Updates the SystemCoreClock with current core Clock retrieved from cpu registers. 50 | */ 51 | extern void SystemCoreClockUpdate (void); 52 | 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* SYSTEM_stm32f4xx_H */ 59 | -------------------------------------------------------------------------------- /Source_code/016_cmsis_task_scheduler/driver/Device/ST/ST/stm32f4xx/Source/system_stm32f4xx.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file system_stm32f4xx.c 3 | * @brief CMSIS Cortex-M# Device Peripheral Access Layer Source File for 4 | * Device stm32f4xx 5 | * @version V5.00 6 | * @date 10. January 2018 7 | ******************************************************************************/ 8 | /* 9 | * Copyright (c) 2009-2018 Arm Limited. All rights reserved. 10 | * 11 | * SPDX-License-Identifier: Apache-2.0 12 | * 13 | * Licensed under the Apache License, Version 2.0 (the License); you may 14 | * not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at 16 | * 17 | * www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 21 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | */ 25 | 26 | #include 27 | #include "stm32f4xx.h" 28 | 29 | 30 | /*---------------------------------------------------------------------------- 31 | Define clocks 32 | *----------------------------------------------------------------------------*/ 33 | /* ToDo: add here your necessary defines for device initialization 34 | following is an example for different system frequencies */ 35 | #define XTAL (12000000U) /* Oscillator frequency */ 36 | 37 | #define SYSTEM_CLOCK (5 * XTAL) 38 | 39 | 40 | /*---------------------------------------------------------------------------- 41 | System Core Clock Variable 42 | *----------------------------------------------------------------------------*/ 43 | /* ToDo: initialize SystemCoreClock with the system core clock frequency value 44 | achieved after system intitialization. 45 | This means system core clock frequency after call to SystemInit() */ 46 | uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Clock Frequency (Core Clock)*/ 47 | 48 | 49 | 50 | /*---------------------------------------------------------------------------- 51 | Clock functions 52 | *----------------------------------------------------------------------------*/ 53 | 54 | void SystemCoreClockUpdate (void) /* Get Core Clock Frequency */ 55 | { 56 | /* ToDo: add code to calculate the system frequency based upon the current 57 | register settings. 58 | This function can be used to retrieve the system core clock frequeny 59 | after user changed register sittings. */ 60 | SystemCoreClock = SYSTEM_CLOCK; 61 | } 62 | 63 | void SystemInit (void) 64 | { 65 | /* ToDo: add code to initialize the system 66 | do not use global variables because this function is called before 67 | reaching pre-main. RW section maybe overwritten afterwards. */ 68 | SystemCoreClock = SYSTEM_CLOCK; 69 | } 70 | -------------------------------------------------------------------------------- /Source_code/RemoteSystemsTempFiles/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | RemoteSystemsTempFiles 4 | 5 | 6 | 7 | 8 | 9 | 10 | org.eclipse.rse.ui.remoteSystemsTempNature 11 | 12 | 13 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Access_level/DebugConfig/Target_1_STM32F407VGTx.dbgconf: -------------------------------------------------------------------------------- 1 | // <<< Use Configuration Wizard in Context Menu >>> 2 | 3 | // Debug MCU Configuration 4 | // DBG_SLEEP Debug Sleep Mode 5 | // DBG_STOP Debug Stop Mode 6 | // DBG_STANDBY Debug Standby Mode 7 | // 8 | DbgMCU_CR = 0x00000007; 9 | 10 | // Debug MCU APB1 Freeze 11 | // DBG_TIM2_STOP Timer 2 Stopped when Core is halted 12 | // DBG_TIM3_STOP Timer 3 Stopped when Core is halted 13 | // DBG_TIM4_STOP Timer 4 Stopped when Core is halted 14 | // DBG_TIM5_STOP Timer 5 Stopped when Core is halted 15 | // DBG_TIM6_STOP Timer 6 Stopped when Core is halted 16 | // DBG_TIM7_STOP Timer 7 Stopped when Core is halted 17 | // DBG_TIM12_STOP Timer 12 Stopped when Core is halted 18 | // DBG_TIM13_STOP Timer 13 Stopped when Core is halted 19 | // DBG_TIM14_STOP Timer 14 Stopped when Core is halted 20 | // DBG_RTC_STOP RTC Stopped when Core is halted 21 | // DBG_WWDG_STOP Window Watchdog Stopped when Core is halted 22 | // DBG_IWDG_STOP Independent Watchdog Stopped when Core is halted 23 | // DBG_I2C1_SMBUS_TIMEOUT I2C1 SMBUS Timeout Mode Stopped when Core is halted 24 | // DBG_I2C2_SMBUS_TIMEOUT I2C2 SMBUS Timeout Mode Stopped when Core is halted 25 | // DBG_I2C3_SMBUS_TIMEOUT I2C3 SMBUS Timeout Mode Stopped when Core is halted 26 | // DBG_CAN1_STOP CAN1 Stopped when Core is halted 27 | // DBG_CAN2_STOP CAN2 Stopped when Core is halted 28 | // 29 | DbgMCU_APB1_Fz = 0x00000000; 30 | 31 | 32 | // Debug MCU APB2 Freeze 33 | // DBG_TIM1_STOP Timer 1 Stopped when Core is halted 34 | // DBG_TIM8_STOP Timer 8 Stopped when Core is halted 35 | // DBG_TIM9_STOP Timer 9 Stopped when Core is halted 36 | // DBG_TIM10_STOP Timer 10 Stopped when Core is halted 37 | // DBG_TIM11_STOP Timer 11 Stopped when Core is halted 38 | // 39 | DbgMCU_APB2_Fz = 0x00000000; 40 | 41 | // <<< end of configuration section >>> -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Access_level/EventRecorderStub.scvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Access_level/Objects/ExtDll.iex: -------------------------------------------------------------------------------- 1 | [EXTDLL] 2 | Count=0 3 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Access_level/Objects/main.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niekiran/CortexMxProgramming/d2ac2ef41bd7af598de6404adbafc5a5fb7fd34d/old/Source_codes/KEIL-MDK-5/Access_level/Objects/main.crf -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Access_level/Objects/system_stm32f4xx.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niekiran/CortexMxProgramming/d2ac2ef41bd7af598de6404adbafc5a5fb7fd34d/old/Source_codes/KEIL-MDK-5/Access_level/Objects/system_stm32f4xx.crf -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Access_level/RTE/_Target_1/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'switching_access_level' 7 | * Target: 'Target 1' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f4xx.h" 18 | 19 | #define RTE_DEVICE_STARTUP_STM32F4XX /* Device Startup for STM32F4 */ 20 | 21 | #endif /* RTE_COMPONENTS_H */ 22 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Access_level/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include "stm32f407xx.h" 3 | 4 | //we have to implement the watchdog interrupt handler 5 | 6 | void WWDG_IRQHandler(void) 7 | { 8 | for(int i=0 ; i < 50 ; i++); 9 | 10 | /* Lets try to move the processor to privileged access level */ 11 | uint32_t value = __get_CONTROL(); 12 | value &= ~0x01; 13 | __set_CONTROL(value); 14 | 15 | } 16 | 17 | void generate_interrupt(void) 18 | { 19 | //Lets simulate the watchdog interrupt 20 | NVIC_EnableIRQ(WWDG_IRQn); 21 | NVIC_SetPendingIRQ(WWDG_IRQn); 22 | } 23 | 24 | void call_application_Task(void) 25 | { 26 | /* This is user appilcation task */ 27 | 28 | /* Lets try to move the processor to privileged access level */ 29 | uint32_t value = __get_CONTROL(); 30 | value &= ~0x01; 31 | __set_CONTROL(value); 32 | 33 | generate_interrupt(); 34 | } 35 | 36 | void RTOS_init(void) 37 | { 38 | /*does RTOS related low level inits */ 39 | 40 | /*before calling application task , change the access level to un-privileged 41 | access level */ 42 | uint32_t value = __get_CONTROL(); 43 | value |= 0x01; 44 | __set_CONTROL(value); 45 | 46 | call_application_Task(); 47 | } 48 | 49 | int main(void) 50 | { 51 | NVIC_EnableIRQ(WWDG_IRQn); 52 | RTOS_init(); 53 | while(1); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Operational_mode/DebugConfig/Target_1_STM32F407VGTx.dbgconf: -------------------------------------------------------------------------------- 1 | // <<< Use Configuration Wizard in Context Menu >>> 2 | 3 | // Debug MCU Configuration 4 | // DBG_SLEEP Debug Sleep Mode 5 | // DBG_STOP Debug Stop Mode 6 | // DBG_STANDBY Debug Standby Mode 7 | // 8 | DbgMCU_CR = 0x00000007; 9 | 10 | // Debug MCU APB1 Freeze 11 | // DBG_TIM2_STOP Timer 2 Stopped when Core is halted 12 | // DBG_TIM3_STOP Timer 3 Stopped when Core is halted 13 | // DBG_TIM4_STOP Timer 4 Stopped when Core is halted 14 | // DBG_TIM5_STOP Timer 5 Stopped when Core is halted 15 | // DBG_TIM6_STOP Timer 6 Stopped when Core is halted 16 | // DBG_TIM7_STOP Timer 7 Stopped when Core is halted 17 | // DBG_TIM12_STOP Timer 12 Stopped when Core is halted 18 | // DBG_TIM13_STOP Timer 13 Stopped when Core is halted 19 | // DBG_TIM14_STOP Timer 14 Stopped when Core is halted 20 | // DBG_RTC_STOP RTC Stopped when Core is halted 21 | // DBG_WWDG_STOP Window Watchdog Stopped when Core is halted 22 | // DBG_IWDG_STOP Independent Watchdog Stopped when Core is halted 23 | // DBG_I2C1_SMBUS_TIMEOUT I2C1 SMBUS Timeout Mode Stopped when Core is halted 24 | // DBG_I2C2_SMBUS_TIMEOUT I2C2 SMBUS Timeout Mode Stopped when Core is halted 25 | // DBG_I2C3_SMBUS_TIMEOUT I2C3 SMBUS Timeout Mode Stopped when Core is halted 26 | // DBG_CAN1_STOP CAN1 Stopped when Core is halted 27 | // DBG_CAN2_STOP CAN2 Stopped when Core is halted 28 | // 29 | DbgMCU_APB1_Fz = 0x00000000; 30 | 31 | 32 | // Debug MCU APB2 Freeze 33 | // DBG_TIM1_STOP Timer 1 Stopped when Core is halted 34 | // DBG_TIM8_STOP Timer 8 Stopped when Core is halted 35 | // DBG_TIM9_STOP Timer 9 Stopped when Core is halted 36 | // DBG_TIM10_STOP Timer 10 Stopped when Core is halted 37 | // DBG_TIM11_STOP Timer 11 Stopped when Core is halted 38 | // 39 | DbgMCU_APB2_Fz = 0x00000000; 40 | 41 | // <<< end of configuration section >>> -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Operational_mode/EventRecorderStub.scvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Operational_mode/Objects/ExtDll.iex: -------------------------------------------------------------------------------- 1 | [EXTDLL] 2 | Count=0 3 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Operational_mode/Objects/main.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niekiran/CortexMxProgramming/d2ac2ef41bd7af598de6404adbafc5a5fb7fd34d/old/Source_codes/KEIL-MDK-5/Operational_mode/Objects/main.crf -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Operational_mode/Objects/system_stm32f4xx.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niekiran/CortexMxProgramming/d2ac2ef41bd7af598de6404adbafc5a5fb7fd34d/old/Source_codes/KEIL-MDK-5/Operational_mode/Objects/system_stm32f4xx.crf -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Operational_mode/RTE/_Target_1/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'Operational_mode' 7 | * Target: 'Target 1' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f4xx.h" 18 | 19 | #define RTE_DEVICE_STARTUP_STM32F4XX /* Device Startup for STM32F4 */ 20 | 21 | #endif /* RTE_COMPONENTS_H */ 22 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Operational_mode/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include "stm32f407xx.h" 3 | 4 | //we have to implement the watchdog interrupt handler 5 | 6 | void WWDG_IRQHandler(void) 7 | { 8 | for(int i=0 ; i < 50 ; i++); 9 | 10 | } 11 | 12 | void generate_interrupt(void) 13 | { 14 | //Lets simulate the watchdog interrupt 15 | NVIC_EnableIRQ(WWDG_IRQn); 16 | NVIC_SetPendingIRQ(WWDG_IRQn); 17 | } 18 | 19 | int main(void) 20 | { 21 | generate_interrupt(); 22 | while(1); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Reset_Sequence/DebugConfig/Target_1_STM32F407VGTx.dbgconf: -------------------------------------------------------------------------------- 1 | // <<< Use Configuration Wizard in Context Menu >>> 2 | 3 | // Debug MCU Configuration 4 | // DBG_SLEEP Debug Sleep Mode 5 | // DBG_STOP Debug Stop Mode 6 | // DBG_STANDBY Debug Standby Mode 7 | // 8 | DbgMCU_CR = 0x00000007; 9 | 10 | // Debug MCU APB1 Freeze 11 | // DBG_TIM2_STOP Timer 2 Stopped when Core is halted 12 | // DBG_TIM3_STOP Timer 3 Stopped when Core is halted 13 | // DBG_TIM4_STOP Timer 4 Stopped when Core is halted 14 | // DBG_TIM5_STOP Timer 5 Stopped when Core is halted 15 | // DBG_TIM6_STOP Timer 6 Stopped when Core is halted 16 | // DBG_TIM7_STOP Timer 7 Stopped when Core is halted 17 | // DBG_TIM12_STOP Timer 12 Stopped when Core is halted 18 | // DBG_TIM13_STOP Timer 13 Stopped when Core is halted 19 | // DBG_TIM14_STOP Timer 14 Stopped when Core is halted 20 | // DBG_RTC_STOP RTC Stopped when Core is halted 21 | // DBG_WWDG_STOP Window Watchdog Stopped when Core is halted 22 | // DBG_IWDG_STOP Independent Watchdog Stopped when Core is halted 23 | // DBG_I2C1_SMBUS_TIMEOUT I2C1 SMBUS Timeout Mode Stopped when Core is halted 24 | // DBG_I2C2_SMBUS_TIMEOUT I2C2 SMBUS Timeout Mode Stopped when Core is halted 25 | // DBG_I2C3_SMBUS_TIMEOUT I2C3 SMBUS Timeout Mode Stopped when Core is halted 26 | // DBG_CAN1_STOP CAN1 Stopped when Core is halted 27 | // DBG_CAN2_STOP CAN2 Stopped when Core is halted 28 | // 29 | DbgMCU_APB1_Fz = 0x00000000; 30 | 31 | 32 | // Debug MCU APB2 Freeze 33 | // DBG_TIM1_STOP Timer 1 Stopped when Core is halted 34 | // DBG_TIM8_STOP Timer 8 Stopped when Core is halted 35 | // DBG_TIM9_STOP Timer 9 Stopped when Core is halted 36 | // DBG_TIM10_STOP Timer 10 Stopped when Core is halted 37 | // DBG_TIM11_STOP Timer 11 Stopped when Core is halted 38 | // 39 | DbgMCU_APB2_Fz = 0x00000000; 40 | 41 | // <<< end of configuration section >>> -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Reset_Sequence/EventRecorderStub.scvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Reset_Sequence/Objects/ExtDll.iex: -------------------------------------------------------------------------------- 1 | [EXTDLL] 2 | Count=0 3 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Reset_Sequence/Objects/main.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niekiran/CortexMxProgramming/d2ac2ef41bd7af598de6404adbafc5a5fb7fd34d/old/Source_codes/KEIL-MDK-5/Reset_Sequence/Objects/main.crf -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Reset_Sequence/Objects/system_stm32f4xx.crf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/niekiran/CortexMxProgramming/d2ac2ef41bd7af598de6404adbafc5a5fb7fd34d/old/Source_codes/KEIL-MDK-5/Reset_Sequence/Objects/system_stm32f4xx.crf -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Reset_Sequence/RTE/_Target_1/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'reset_Sequence' 7 | * Target: 'Target 1' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f4xx.h" 18 | 19 | #define RTE_DEVICE_STARTUP_STM32F4XX /* Device Startup for STM32F4 */ 20 | 21 | #endif /* RTE_COMPONENTS_H */ 22 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Reset_Sequence/main.c: -------------------------------------------------------------------------------- 1 | 2 | extern void SystemInit(void); 3 | extern int __main(void); 4 | 5 | int main(void) 6 | { 7 | 8 | return 0; 9 | 10 | } 11 | 12 | void Reset_Handler(void) 13 | { 14 | SystemInit(); 15 | __main(); 16 | 17 | } -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 11_ (60) Stacks/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Write a program to PUSH the contents of R0,R1,R2 Registers 3 | using MSP as a stack pointer, and then POP the contents back using PSP as a stack pointer 4 | */ 5 | 6 | #include 7 | #include "stm32f407xx.h" 8 | 9 | extern void do_stack_operations(void); 10 | int main() 11 | { 12 | /* This function is implemeted in Assembly */ 13 | do_stack_operations(); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 11_ (60) Stacks/stack_op.s: -------------------------------------------------------------------------------- 1 | 2 | AREA STACK_OP, CODE, READONLY 3 | EXPORT do_stack_operations 4 | do_stack_operations 5 | MOV R0,#0x11 6 | MOV R1,#0X22 7 | MOV R2,#0X33 8 | PUSH {R0-R2} ; PUSH the contents of RO,R1,R2 9 | MRS R0,CONTROL ; Read the Contents of CONTROL register 10 | ORR R0,R0,#0X02 ; set the SPSEL bit to 1, to select PSP 11 | MSR CONTROL,R0 ; Write back to the CONTROL register 12 | MRS R0,MSP 13 | MSR PSP,R0 ; Initialize the PSP 14 | POP {R0-R2} ; POP back 15 | 16 | BX lr ; Return. 17 | END -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 13_ (76) Exception masking & unmasking/led.c: -------------------------------------------------------------------------------- 1 | 2 | #include "my_board.h" 3 | #include "stm32f407xx.h" 4 | 5 | 6 | void led_init() 7 | { 8 | 9 | RCC->AHB1ENR |= (0x08 ); 10 | 11 | //configure LED_4 . YELLOW 12 | GPIOD->MODER |= (0x01 << (LED_4 * 2)); 13 | GPIOD->OTYPER |= ( 0 << LED_4); 14 | GPIOD->PUPDR |= (0x00 << (LED_4 * 2)); 15 | GPIOD->OSPEEDR |= (0X00 << (LED_4 * 2)); 16 | 17 | 18 | //configure LED_3 . SAFFRON 19 | GPIOD->MODER |= (0x01 << (LED_3 * 2)); 20 | GPIOD->OTYPER |= ( 0 << LED_3); 21 | GPIOD->PUPDR |= (0x00 << (LED_3 * 2)); 22 | GPIOD->OSPEEDR |= (0X00 << (LED_3 * 2)); 23 | 24 | 25 | //configure LED_5 . RED 26 | GPIOD->MODER |= (0x01 << (LED_5 * 2)); 27 | GPIOD->OTYPER |= ( 0 << LED_5); 28 | GPIOD->PUPDR |= (0x00 << (LED_5 * 2)); 29 | GPIOD->OSPEEDR |= (0X00 << (LED_5 * 2)); 30 | 31 | 32 | //configure LED_6 . BLUE 33 | GPIOD->MODER |= (0x01 << (LED_6 * 2)); 34 | GPIOD->OTYPER |= ( 0 << LED_6); 35 | GPIOD->PUPDR |= (0x00 << (LED_6 * 2)); 36 | GPIOD->OSPEEDR |= (0X00 << (LED_6 * 2)); 37 | 38 | } 39 | 40 | 41 | void led_on(uint8_t led_no) 42 | { 43 | GPIOD->BSRR = ( 1 << led_no ); 44 | } 45 | 46 | void led_off(uint8_t led_no) 47 | { 48 | GPIOD->BSRR = ( 1 << (led_no+16) ); 49 | } 50 | 51 | 52 | void led_toggle(uint8_t led_no) 53 | { 54 | if(GPIOD->ODR & (1 << led_no) ) 55 | { 56 | led_off(led_no); 57 | }else 58 | { 59 | led_on(led_no); 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 13_ (76) Exception masking & unmasking/led.h: -------------------------------------------------------------------------------- 1 | #ifndef __LED_H_ 2 | #define __LED_H_ 3 | 4 | void led_init(void); 5 | void led_on(uint8_t led_no); 6 | void led_off(uint8_t led_no); 7 | void led_toggle(uint8_t led_no); 8 | 9 | #endif -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 13_ (76) Exception masking & unmasking/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stm32f407xx.h" 3 | #include "led.h" 4 | #include "my_board.h" 5 | 6 | 7 | void button_init(void) 8 | { 9 | /* Enable GPIOA clock */ 10 | /* because BUTTON is connected to GPIOA */ 11 | RCC->AHB1ENR |= 0x01; 12 | 13 | //set the mode 14 | GPIOA->MODER &= ~0x3; 15 | GPIOA->PUPDR &= ~0x3; 16 | 17 | //enable clock for RCC 18 | RCC->APB2ENR |= 0x00004000; 19 | 20 | //configure the interrupt 21 | EXTI->IMR |= 0x01; 22 | // EXTI->RTSR |= 0X01; 23 | EXTI->FTSR |= 0X01; 24 | 25 | //nvic configuration 26 | /* if BASEPRI = 0X80, and making IP[EXTI0_IRQn] = 0X90 will block the interrupt 27 | if BASEPRI = 0X80, and making IP[EXTI0_IRQn] = 0X00 will allow the interrupt 28 | */ 29 | NVIC->IP[EXTI0_IRQn] = 0x00; 30 | NVIC_EnableIRQ(EXTI0_IRQn); 31 | 32 | 33 | } 34 | 35 | 36 | 37 | 38 | /** 39 | * @brief Main program 40 | * @param None 41 | * @retval None 42 | */ 43 | int main(void) 44 | { 45 | 46 | led_init(); 47 | 48 | /* Configure EXTI Line0 (connected to PA0 pin) in interrupt mode */ 49 | button_init(); 50 | 51 | #if 1 52 | __set_PRIMASK(1); 53 | #endif 54 | 55 | #if 0 56 | /* 0x80 is the priority level, any interrupt which is same or lower priority will be blocked */ 57 | __set_BASEPRI(0X80); 58 | #endif 59 | 60 | 61 | /* Infinite loop */ 62 | while (1) 63 | { 64 | } 65 | } 66 | 67 | 68 | 69 | /* ISR to handle BUTTON interrupt */ 70 | 71 | void EXTI0_IRQHandler(void) 72 | { 73 | led_toggle(LED_4); 74 | 75 | /*clear the exti0 interrupt pending bit */ 76 | if( (EXTI->PR & 0x01) ) 77 | { 78 | EXTI->PR &= 0x01; 79 | 80 | } 81 | } 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 13_ (76) Exception masking & unmasking/my_board.h: -------------------------------------------------------------------------------- 1 | #ifndef __MY_BOARD_H 2 | #define __MY_BOARD_H 3 | 4 | #define GPIO_PIN_12 12 5 | #define GPIO_PIN_13 13 6 | #define GPIO_PIN_14 14 7 | #define GPIO_PIN_15 15 8 | 9 | 10 | #define LED_4 GPIO_PIN_12 11 | #define LED_3 GPIO_PIN_13 12 | #define LED_5 GPIO_PIN_14 13 | #define LED_6 GPIO_PIN_15 14 | 15 | #endif -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 13_ (78) Interrupt priority and preemption/led.c: -------------------------------------------------------------------------------- 1 | 2 | #include "my_board.h" 3 | #include "stm32f407xx.h" 4 | 5 | 6 | void led_init() 7 | { 8 | 9 | RCC->AHB1ENR |= (0x08 ); 10 | 11 | //configure LED_4 . YELLOW 12 | GPIOD->MODER |= (0x01 << (LED_4 * 2)); 13 | GPIOD->OTYPER |= ( 0 << LED_4); 14 | GPIOD->PUPDR |= (0x00 << (LED_4 * 2)); 15 | GPIOD->OSPEEDR |= (0X00 << (LED_4 * 2)); 16 | 17 | 18 | //configure LED_3 . SAFFRON 19 | GPIOD->MODER |= (0x01 << (LED_3 * 2)); 20 | GPIOD->OTYPER |= ( 0 << LED_3); 21 | GPIOD->PUPDR |= (0x00 << (LED_3 * 2)); 22 | GPIOD->OSPEEDR |= (0X00 << (LED_3 * 2)); 23 | 24 | 25 | //configure LED_5 . RED 26 | GPIOD->MODER |= (0x01 << (LED_5 * 2)); 27 | GPIOD->OTYPER |= ( 0 << LED_5); 28 | GPIOD->PUPDR |= (0x00 << (LED_5 * 2)); 29 | GPIOD->OSPEEDR |= (0X00 << (LED_5 * 2)); 30 | 31 | 32 | //configure LED_6 . BLUE 33 | GPIOD->MODER |= (0x01 << (LED_6 * 2)); 34 | GPIOD->OTYPER |= ( 0 << LED_6); 35 | GPIOD->PUPDR |= (0x00 << (LED_6 * 2)); 36 | GPIOD->OSPEEDR |= (0X00 << (LED_6 * 2)); 37 | 38 | } 39 | 40 | 41 | void led_on(uint8_t led_no) 42 | { 43 | GPIOD->BSRR = ( 1 << led_no ); 44 | } 45 | 46 | void led_off(uint8_t led_no) 47 | { 48 | GPIOD->BSRR = ( 1 << (led_no+16) ); 49 | } 50 | 51 | 52 | void led_toggle(uint8_t led_no) 53 | { 54 | if(GPIOD->ODR & (1 << led_no) ) 55 | { 56 | led_off(led_no); 57 | }else 58 | { 59 | led_on(led_no); 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 13_ (78) Interrupt priority and preemption/led.h: -------------------------------------------------------------------------------- 1 | #ifndef __LED_H_ 2 | #define __LED_H_ 3 | 4 | void led_init(void); 5 | void led_on(uint8_t led_no); 6 | void led_off(uint8_t led_no); 7 | void led_toggle(uint8_t led_no); 8 | 9 | #endif -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 13_ (78) Interrupt priority and preemption/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stm32f407xx.h" 3 | #include "led.h" 4 | #include "my_board.h" 5 | 6 | /* highest */ 7 | #define HIGH_PRIORITY_VAL_1 0X00 8 | /*lowest*/ 9 | #define LOW_PRIORITY_VAL_1 0XF0 10 | 11 | #define HIGH_PRIORITY_VAL_2 0X10 12 | #define LOW_PRIORITY_VAL_2 0XE0 13 | 14 | void button_init(void) 15 | { 16 | /* Enable GPIOA clock */ 17 | /* because BUTTON is connected to GPIOA */ 18 | RCC->AHB1ENR |= 0x01; 19 | 20 | //set the mode 21 | GPIOA->MODER &= ~0x3; 22 | GPIOA->PUPDR &= ~0x3; 23 | 24 | //enable clock for RCC 25 | RCC->APB2ENR |= 0x00004000; 26 | 27 | //configure the interrupt 28 | EXTI->IMR |= 0x01; 29 | // EXTI->RTSR |= 0X01; 30 | EXTI->FTSR |= 0X01; 31 | 32 | 33 | //nvic configuration 34 | /* button is irq number 6. which is connected over EXTI0 line in stm32f4xx */ 35 | NVIC->IP[EXTI0_IRQn] = 0Xf0;// (low priority ) 36 | NVIC_EnableIRQ(EXTI0_IRQn); 37 | 38 | 39 | 40 | 41 | } 42 | 43 | 44 | /** 45 | * @brief Main program 46 | * @param None 47 | * @retval None 48 | */ 49 | int main(void) 50 | { 51 | uint32_t val; 52 | led_init(); 53 | 54 | /*configure systick timing */ 55 | //2000 ticks 56 | SysTick_Config(2000);//125 micro seconds 57 | 58 | /*configure Systick priority and enable it */ 59 | SCB->SHP[0x0B] = 0X00;// ( high priority) 60 | NVIC_EnableIRQ(SysTick_IRQn); 61 | 62 | 63 | 64 | /* Configure EXTI Line0 (connected to PA0 pin) in interrupt mode */ 65 | button_init(); 66 | 67 | 68 | /* Infinite loop */ 69 | while (1) 70 | { 71 | 72 | } 73 | } 74 | 75 | /* ISR for button interrupt */ 76 | void EXTI0_IRQHandler(void) 77 | { 78 | 79 | int i=0; 80 | /* clear the interrupt pending bit of exti0*/ 81 | if( (EXTI->PR & 0x01) ) 82 | { 83 | EXTI->PR &= 0x01; 84 | 85 | } 86 | //PD12 87 | led_on(LED_4); 88 | for(i=0;i<50000;i++); //do some work 89 | led_off(LED_4); 90 | } 91 | 92 | /* SysTick Exception handler */ 93 | void SysTick_Handler(void) 94 | { 95 | 96 | //PD13 97 | led_on(LED_3); 98 | led_off(LED_3); 99 | 100 | } 101 | 102 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 13_ (78) Interrupt priority and preemption/my_board.h: -------------------------------------------------------------------------------- 1 | #ifndef __MY_BOARD_H 2 | #define __MY_BOARD_H 3 | 4 | #define GPIO_PIN_12 12 5 | #define GPIO_PIN_13 13 6 | #define GPIO_PIN_14 14 7 | #define GPIO_PIN_15 15 8 | 9 | 10 | #define LED_4 GPIO_PIN_12 11 | #define LED_3 GPIO_PIN_13 12 | #define LED_5 GPIO_PIN_14 13 | #define LED_6 GPIO_PIN_15 14 | 15 | #endif -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 15_ (82) Toggle LED using registers/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stm32f407xx.h" 3 | 4 | /* offest of the AHB1ENR register from RCC block */ 5 | #define RCC_AHB1ENR_OFFSET 0x30 6 | 7 | /* Base address of the RCC.. we got this address by looking into memory map */ 8 | #define RCC_BASE_ADDR (0x40023800) 9 | 10 | /* actual address of the RCC_AHB1ENR Register */ 11 | #define RCC_AHB1ENR_ADDR *((volatile unsigned long *)(RCC_BASE_ADDR + RCC_AHB1ENR_OFFSET) ) 12 | 13 | #define GPIOD_MODER_OFFSET 0X00 14 | 15 | #define BASE_ADDR_GPIOD (0x40020C00) 16 | 17 | #define GPIOD_MODER *((volatile unsigned long *)(BASE_ADDR_GPIOD + GPIOD_MODER_OFFSET)) 18 | 19 | #define OFFSET_OF_OUTPU_DATA_REG 0X14 20 | #define GPIOD_OPDATAREG *( (volatile unsigned long *)(BASE_ADDR_GPIOD+OFFSET_OF_OUTPU_DATA_REG)) 21 | 22 | #define OFFSET_OF_INPUT_DATA_REG 0X10 23 | #define GPIOD_IPDATAREG *( (volatile unsigned long *)(BASE_ADDR_GPIOD+OFFSET_OF_INPUT_DATA_REG)) 24 | 25 | void toggle_led(void) 26 | { 27 | 28 | if(GPIOD_IPDATAREG & (1<<12) ) 29 | { 30 | //LED IS on , turn if off 31 | GPIOD_OPDATAREG &= ~(1<<12); 32 | }else 33 | { 34 | GPIOD_OPDATAREG |= (1<<12); 35 | } 36 | } 37 | 38 | int main(void) 39 | { 40 | uint32_t i=0; 41 | /* 1. Enable the clock for GPIOD port */ 42 | RCC_AHB1ENR_ADDR |= (1<<3);//bit 3 enables the clock for the GPIOD port 43 | 44 | /* 2. Configure the GPIO PIN to output mode using MODE register */ 45 | 46 | GPIOD_MODER |= (1 << (12 * 2)); //set 24th bit and 25 bit to 0x01 to make 12pin output 47 | 48 | /* 3. use the DATA REGISTER of GPIOD port to write to or read from LED */ 49 | 50 | GPIOD_OPDATAREG |= (1<<12);//turn the led4 on. remember led 4 is connected to GPIOD PIN 12 51 | 52 | while(1) 53 | { 54 | toggle_led(); 55 | for(i=0;i<500000;i++); 56 | toggle_led(); 57 | for(i=0;i<500000;i++); 58 | } 59 | 60 | return 0; 61 | } -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 15_ External Interrupts-Buttons/led.c: -------------------------------------------------------------------------------- 1 | 2 | #include "my_board.h" 3 | #include 4 | 5 | 6 | void led_init() 7 | { 8 | 9 | RCC->AHB1ENR |= (0x08 ); 10 | 11 | //configure LED_4 . YELLOW 12 | GPIOD->MODER |= (0x01 << (LED_4 * 2)); 13 | GPIOD->OTYPER |= ( 0 << LED_4); 14 | GPIOD->PUPDR |= (0x00 << (LED_4 * 2)); 15 | GPIOD->OSPEEDR |= (0X00 << (LED_4 * 2)); 16 | 17 | 18 | //configure LED_3 . SAFFRON 19 | GPIOD->MODER |= (0x01 << (LED_3 * 2)); 20 | GPIOD->OTYPER |= ( 0 << LED_3); 21 | GPIOD->PUPDR |= (0x00 << (LED_3 * 2)); 22 | GPIOD->OSPEEDR |= (0X00 << (LED_3 * 2)); 23 | 24 | 25 | //configure LED_5 . RED 26 | GPIOD->MODER |= (0x01 << (LED_5 * 2)); 27 | GPIOD->OTYPER |= ( 0 << LED_5); 28 | GPIOD->PUPDR |= (0x00 << (LED_5 * 2)); 29 | GPIOD->OSPEEDR |= (0X00 << (LED_5 * 2)); 30 | 31 | 32 | //configure LED_6 . BLUE 33 | GPIOD->MODER |= (0x01 << (LED_6 * 2)); 34 | GPIOD->OTYPER |= ( 0 << LED_6); 35 | GPIOD->PUPDR |= (0x00 << (LED_6 * 2)); 36 | GPIOD->OSPEEDR |= (0X00 << (LED_6 * 2)); 37 | 38 | } 39 | 40 | 41 | void led_on(uint8_t led_no) 42 | { 43 | GPIOD->BSRR = ( 1 << led_no ); 44 | } 45 | 46 | void led_off(uint8_t led_no) 47 | { 48 | GPIOD->BSRR = ( 1 << (led_no+16) ); 49 | } 50 | 51 | 52 | void led_toggle(uint8_t led_no) 53 | { 54 | if(GPIOD->ODR & (1 << led_no) ) 55 | { 56 | led_off(led_no); 57 | }else 58 | { 59 | led_on(led_no); 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 15_ External Interrupts-Buttons/led.h: -------------------------------------------------------------------------------- 1 | #ifndef __LED_H_ 2 | #define __LED_H_ 3 | 4 | void led_init(void); 5 | void led_on(uint8_t led_no); 6 | void led_off(uint8_t led_no); 7 | void led_toggle(uint8_t led_no); 8 | 9 | #endif -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 15_ External Interrupts-Buttons/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "stm32f407xx.h" 4 | #include "led.h" 5 | #include "my_board.h" 6 | 7 | void button_init(void); 8 | 9 | void button_init(void) 10 | { 11 | /*1. Enable GPIOA clock */ 12 | /* because BUTTON is connected to GPIOA PIN0 */ 13 | //RCC_AHB1ENR 14 | RCC->AHB1ENR |= 0X01; //Enables the clock 15 | 16 | 17 | /* 2. set the mode of GPIOA pin0 to "INPUT" */ 18 | GPIOA->MODER &= ~0X03; 19 | 20 | 21 | 22 | /*3. set the interrupt triggering level */ 23 | //(EXTI_FTSR 24 | EXTI->FTSR |= 0X01; 25 | 26 | /*4. enable the interrupt over EXTI0 */ 27 | EXTI->IMR |= 0X01; 28 | 29 | 30 | /*5. the interrupt on NVIC for IRQ6 */ 31 | NVIC->ISER[0] |= ( 1 << EXTI0_IRQn); 32 | 33 | } 34 | 35 | int main() 36 | { 37 | 38 | led_init(); 39 | 40 | button_init(); 41 | 42 | led_on(LED_4); 43 | led_on(LED_3); 44 | led_on(LED_5); 45 | led_on(LED_6); 46 | 47 | /*infinite loop */ 48 | while(1) 49 | { 50 | 51 | } 52 | 53 | return 0; 54 | } 55 | 56 | void EXTI0_IRQHandler(void) 57 | { 58 | /*clear the pending bit for exti0 */ 59 | if( (EXTI->PR & 0x01) ) 60 | { 61 | EXTI->PR = 0x01;//Writing 1 , clears the pending bit for exti0 62 | 63 | } 64 | led_toggle(LED_4); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 15_ External Interrupts-Buttons/my_board.h: -------------------------------------------------------------------------------- 1 | #ifndef __MY_BOARD_H 2 | #define __MY_BOARD_H 3 | 4 | #define GPIO_PIN_12 12 5 | #define GPIO_PIN_13 13 6 | #define GPIO_PIN_14 14 7 | #define GPIO_PIN_15 15 8 | 9 | 10 | #define LED_4 GPIO_PIN_12 11 | #define LED_3 GPIO_PIN_13 12 | #define LED_5 GPIO_PIN_14 13 | #define LED_6 GPIO_PIN_15 14 | 15 | #endif -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 17_ (80) SVC exception/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /*This is how you execute a SVC instruction in c 5 | compiler will replace this functin call by "svc 0x36" instruction */ 6 | int __svc(0x36) svc_service_add(int x , int y); 7 | 8 | int SVC_Handler_C(unsigned int *svc_args); 9 | 10 | int result = 0; 11 | 12 | int main(void) 13 | { 14 | int x , y; 15 | 16 | x = 0x17, y =0x27; 17 | 18 | /* below line will be replaced by svc instruction */ 19 | result = svc_service_add(x,y); 20 | 21 | while(1); 22 | 23 | } 24 | 25 | 26 | 27 | int SVC_Handler_C(unsigned int *svc_args) 28 | { 29 | 30 | uint32_t svc_number; 31 | 32 | /* svc_args[6] will give address of next instruction after "svc 0x36" instruction 33 | (svc_args[6]- 2) will give the address of "svc 0x36" instruction 34 | so *( ((char *)(svc_args[6])) -2 ); will give the value of svc service number 35 | */ 36 | svc_number = *( ((char *)(svc_args[6])) -2 ); 37 | switch(svc_number) 38 | { 39 | case 0x36 : 40 | svc_args[0] = svc_args[0]+svc_args[1]; 41 | break; 42 | 43 | case 0x37 : 44 | svc_args[0] = svc_args[0] * svc_args[1]; 45 | break; 46 | 47 | default: 48 | break; 49 | } 50 | 51 | 52 | return svc_args[0]; 53 | } 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 17_ (80) SVC exception/svc_handler.s: -------------------------------------------------------------------------------- 1 | ;This code only extracts MSP Or PSP value into RO BY testing LR register */ 2 | EXPORT SVC_Handler 3 | AREA SVC_Area, CODE, READONLY 4 | IMPORT SVC_Handler_C ; This is the SVC exception handler 5 | SVC_Handler 6 | TST LR,#4 ; Check the LR bit position 2 , to test which Stack pointer was in use 7 | ;during stacking operation 8 | ITE EQ 9 | MRSEQ R0,MSP ; if LR bit2 is 0, then copy MSP to RO 10 | MRSNE R0,PSP ; if LR bit2 is 1 , then copy PSP TO R0 11 | 12 | B SVC_Handler_C ; Call C function for further processing 13 | END 14 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 17_ (90) PendSV exception/led.c: -------------------------------------------------------------------------------- 1 | 2 | #include "my_board.h" 3 | #include "stm32f407xx.h" 4 | 5 | 6 | void led_init() 7 | { 8 | 9 | RCC->AHB1ENR |= (0x08 ); 10 | 11 | //configure LED_4 . YELLOW 12 | GPIOD->MODER |= (0x01 << (LED_4 * 2)); 13 | GPIOD->OTYPER |= ( 0 << LED_4); 14 | GPIOD->PUPDR |= (0x00 << (LED_4 * 2)); 15 | GPIOD->OSPEEDR |= (0X00 << (LED_4 * 2)); 16 | 17 | 18 | //configure LED_3 . SAFFRON 19 | GPIOD->MODER |= (0x01 << (LED_3 * 2)); 20 | GPIOD->OTYPER |= ( 0 << LED_3); 21 | GPIOD->PUPDR |= (0x00 << (LED_3 * 2)); 22 | GPIOD->OSPEEDR |= (0X00 << (LED_3 * 2)); 23 | 24 | 25 | //configure LED_5 . RED 26 | GPIOD->MODER |= (0x01 << (LED_5 * 2)); 27 | GPIOD->OTYPER |= ( 0 << LED_5); 28 | GPIOD->PUPDR |= (0x00 << (LED_5 * 2)); 29 | GPIOD->OSPEEDR |= (0X00 << (LED_5 * 2)); 30 | 31 | 32 | //configure LED_6 . BLUE 33 | GPIOD->MODER |= (0x01 << (LED_6 * 2)); 34 | GPIOD->OTYPER |= ( 0 << LED_6); 35 | GPIOD->PUPDR |= (0x00 << (LED_6 * 2)); 36 | GPIOD->OSPEEDR |= (0X00 << (LED_6 * 2)); 37 | 38 | } 39 | 40 | 41 | void led_on(uint8_t led_no) 42 | { 43 | GPIOD->BSRR = ( 1 << led_no ); 44 | } 45 | 46 | void led_off(uint8_t led_no) 47 | { 48 | GPIOD->BSRR = ( 1 << (led_no+16) ); 49 | } 50 | 51 | 52 | void led_toggle(uint8_t led_no) 53 | { 54 | if(GPIOD->ODR & (1 << led_no) ) 55 | { 56 | led_off(led_no); 57 | }else 58 | { 59 | led_on(led_no); 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 17_ (90) PendSV exception/led.h: -------------------------------------------------------------------------------- 1 | #ifndef __LED_H_ 2 | #define __LED_H_ 3 | 4 | void led_init(void); 5 | void led_on(uint8_t led_no); 6 | void led_off(uint8_t led_no); 7 | void led_toggle(uint8_t led_no); 8 | 9 | #endif -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 17_ (90) PendSV exception/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stm32f407xx.h" 3 | #include "led.h" 4 | #include "my_board.h" 5 | 6 | 7 | void button_init(void) 8 | { 9 | /* Enable GPIOA clock */ 10 | /* because BUTTON is connected to GPIOA */ 11 | RCC->AHB1ENR |= 0x01; 12 | 13 | //set the mode 14 | GPIOA->MODER &= ~0x3; 15 | GPIOA->PUPDR &= ~0x3; 16 | 17 | //enable clock for RCC 18 | RCC->APB2ENR |= 0x00004000; 19 | 20 | //configure the interrupt 21 | EXTI->IMR |= 0x01; 22 | // EXTI->RTSR |= 0X01; 23 | EXTI->FTSR |= 0X01; 24 | 25 | //nvic configuration 26 | NVIC->IP[EXTI0_IRQn] = 0x00; 27 | NVIC_EnableIRQ(EXTI0_IRQn); 28 | 29 | } 30 | 31 | /** 32 | * @brief Main program 33 | * @param None 34 | * @retval None 35 | */ 36 | int main(void) 37 | { 38 | 39 | led_init(); 40 | 41 | /* Configure EXTI Line0 (connected to PA0 pin) in interrupt mode */ 42 | button_init(); 43 | 44 | /* Infinite loop */ 45 | while (1) 46 | { 47 | } 48 | } 49 | 50 | /* ISR for the button interrupt */ 51 | void EXTI0_IRQHandler(void) 52 | { 53 | /* clear EXTI0 pending bit */ 54 | if( (EXTI->PR & 0x01) ) 55 | { 56 | EXTI->PR = 0x01; 57 | } 58 | 59 | led_toggle(LED_4); 60 | /*process only which is important and trigger the pendsv to 61 | handle rest in the pendsv handler */ 62 | SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk; 63 | } 64 | 65 | 66 | /* PendSV Exception handler */ 67 | void PendSV_Handler(void) 68 | { 69 | // bottom half work can be done here. 70 | led_toggle(LED_3); 71 | } 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 17_ (90) PendSV exception/my_board.h: -------------------------------------------------------------------------------- 1 | #ifndef __MY_BOARD_H 2 | #define __MY_BOARD_H 3 | 4 | #define GPIO_PIN_12 12 5 | #define GPIO_PIN_13 13 6 | #define GPIO_PIN_14 14 7 | #define GPIO_PIN_15 15 8 | 9 | 10 | #define LED_4 GPIO_PIN_12 11 | #define LED_3 GPIO_PIN_13 12 | #define LED_5 GPIO_PIN_14 13 | #define LED_6 GPIO_PIN_15 14 | 15 | #endif -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 7_ Access levels/led.c: -------------------------------------------------------------------------------- 1 | 2 | #include "my_board.h" 3 | #include "stm32f407xx.h" 4 | 5 | 6 | void led_init() 7 | { 8 | 9 | RCC->AHB1ENR |= (0x08 ); 10 | 11 | //configure LED_4 . YELLOW 12 | GPIOD->MODER |= (0x01 << (LED_4 * 2)); 13 | GPIOD->OTYPER |= ( 0 << LED_4); 14 | GPIOD->PUPDR |= (0x00 << (LED_4 * 2)); 15 | GPIOD->OSPEEDR |= (0X00 << (LED_4 * 2)); 16 | 17 | 18 | //configure LED_3 . SAFFRON 19 | GPIOD->MODER |= (0x01 << (LED_3 * 2)); 20 | GPIOD->OTYPER |= ( 0 << LED_3); 21 | GPIOD->PUPDR |= (0x00 << (LED_3 * 2)); 22 | GPIOD->OSPEEDR |= (0X00 << (LED_3 * 2)); 23 | 24 | 25 | //configure LED_5 . RED 26 | GPIOD->MODER |= (0x01 << (LED_5 * 2)); 27 | GPIOD->OTYPER |= ( 0 << LED_5); 28 | GPIOD->PUPDR |= (0x00 << (LED_5 * 2)); 29 | GPIOD->OSPEEDR |= (0X00 << (LED_5 * 2)); 30 | 31 | 32 | //configure LED_6 . BLUE 33 | GPIOD->MODER |= (0x01 << (LED_6 * 2)); 34 | GPIOD->OTYPER |= ( 0 << LED_6); 35 | GPIOD->PUPDR |= (0x00 << (LED_6 * 2)); 36 | GPIOD->OSPEEDR |= (0X00 << (LED_6 * 2)); 37 | 38 | } 39 | 40 | 41 | void led_on(uint8_t led_no) 42 | { 43 | GPIOD->BSRR = ( 1 << led_no ); 44 | } 45 | 46 | void led_off(uint8_t led_no) 47 | { 48 | GPIOD->BSRR = ( 1 << (led_no+16) ); 49 | } 50 | 51 | 52 | void led_toggle(uint8_t led_no) 53 | { 54 | if(GPIOD->ODR & (1 << led_no) ) 55 | { 56 | led_off(led_no); 57 | }else 58 | { 59 | led_on(led_no); 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 7_ Access levels/led.h: -------------------------------------------------------------------------------- 1 | #ifndef __LED_H_ 2 | #define __LED_H_ 3 | 4 | void led_init(void); 5 | void led_on(uint8_t led_no); 6 | void led_off(uint8_t led_no); 7 | void led_toggle(uint8_t led_no); 8 | 9 | #endif -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 7_ Access levels/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stm32f407xx.h" 3 | #include "led.h" 4 | #include "my_board.h" 5 | 6 | 7 | int is_privileged_access() 8 | { 9 | if ( (__get_CONTROL() & 0X01 )) 10 | { 11 | return 0;//we are in un privileged mode 12 | } 13 | else 14 | { 15 | return 1;// wer are in prvileged mode 16 | } 17 | 18 | } 19 | 20 | void go_to_unprivileged_access_level() 21 | { 22 | uint32_t val; 23 | val = __get_CONTROL(); 24 | val |= 0x01; //set to unprivileged mode 25 | __set_CONTROL(val); 26 | 27 | 28 | 29 | } 30 | 31 | void go_to_privileged_access_level() 32 | { 33 | uint32_t val; 34 | val = __get_CONTROL(); 35 | val &= ~0x01; //set to privileged mode 36 | __set_CONTROL(val); 37 | 38 | 39 | 40 | } 41 | 42 | void button_init(void) 43 | { 44 | /* Enable GPIOA clock */ 45 | /* because BUTTON is connected to GPIOA */ 46 | RCC->AHB1ENR |= 0x01; 47 | 48 | //set the mode 49 | GPIOA->MODER &= ~0x3; 50 | GPIOA->PUPDR &= ~0x3; 51 | 52 | //enable clock for RCC 53 | RCC->APB2ENR |= 0x00004000; 54 | 55 | //configure the interrupt 56 | EXTI->IMR |= 0x01; 57 | // EXTI->RTSR |= 0X01; 58 | EXTI->FTSR |= 0X01; 59 | 60 | //nvic configuration 61 | NVIC->IP[EXTI0_IRQn] = 0; 62 | NVIC_EnableIRQ(EXTI0_IRQn); 63 | 64 | } 65 | /** 66 | * @brief Main program 67 | * @param None 68 | * @retval None 69 | */ 70 | int main(void) 71 | { 72 | uint32_t val; 73 | led_init(); 74 | 75 | /* Configure EXTI Line0 (connected to PA0 pin) in interrupt mode */ 76 | button_init(); 77 | 78 | if(is_privileged_access()) 79 | { 80 | __set_PRIMASK(1); 81 | __set_PRIMASK(0); 82 | } 83 | 84 | go_to_unprivileged_access_level(); 85 | 86 | __set_PRIMASK(1); 87 | __set_PRIMASK(0); 88 | 89 | go_to_privileged_access_level(); 90 | 91 | __set_PRIMASK(1); 92 | __set_PRIMASK(0); 93 | 94 | 95 | /* Infinite loop */ 96 | while (1) 97 | { 98 | __set_PRIMASK(1); 99 | __set_PRIMASK(0); 100 | 101 | } 102 | } 103 | 104 | 105 | /* ISR for button interrupt */ 106 | void EXTI0_IRQHandler(void) 107 | { 108 | 109 | /* clearn the exti0 pended interrupt*/ 110 | if( (EXTI->PR & 0x01) ) 111 | { 112 | EXTI->PR &= 0x01; 113 | } 114 | 115 | led_toggle(LED_4); 116 | go_to_privileged_access_level(); 117 | 118 | } 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 7_ Access levels/my_board.h: -------------------------------------------------------------------------------- 1 | #ifndef __MY_BOARD_H 2 | #define __MY_BOARD_H 3 | 4 | #define GPIO_PIN_12 12 5 | #define GPIO_PIN_13 13 6 | #define GPIO_PIN_14 14 7 | #define GPIO_PIN_15 15 8 | 9 | 10 | #define LED_4 GPIO_PIN_12 11 | #define LED_3 GPIO_PIN_13 12 | #define LED_5 GPIO_PIN_14 13 | #define LED_6 GPIO_PIN_15 14 | 15 | #endif -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 7_ Cortex-M registers/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "stm32f407xx.h" 4 | 5 | /* This application explains how to get started with using CMSIS core APIs. The Code demonstrates 6 | setting up using CMSIS environemnt with headerfile and its core APIS to read/modify/write some of 7 | the system registers */ 8 | 9 | 10 | int main() 11 | { 12 | uint32_t val; 13 | 14 | __set_PRIMASK(1); 15 | val = __get_PRIMASK(); 16 | 17 | __set_FAULTMASK(1); 18 | val = __get_FAULTMASK(); 19 | 20 | __set_BASEPRI(0x80); 21 | val = __get_BASEPRI(); 22 | 23 | val = __get_MSP(); 24 | __set_MSP(val+4); 25 | 26 | val = __get_PSP(); 27 | __set_PSP(val+4); 28 | 29 | 30 | return 0; 31 | 32 | } -------------------------------------------------------------------------------- /old/Source_codes/KEIL-MDK-5/Section 9_ (51) Bit banding/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define BIT_BAND_REGION_MEM_ADDR_1 *((volatile unsigned long *)(0x20000000)) 4 | 5 | #define BIT_BAND_ALIAS_BASE_ADDRESS (0x22000000) 6 | 7 | /* bit band alias addresses to adddress bit0 , 8 | bit1, bit2 of the bit band memory address BIT_BAND_REGION_MEM_ADDR_1*/ 9 | #define BIT_BAND_ALIAS_ADDRESS_1 *((volatile unsigned long *)(BIT_BAND_ALIAS_BASE_ADDRESS+0)) 10 | #define BIT_BAND_ALIAS_ADDRESS_2 *((volatile unsigned long *)(BIT_BAND_ALIAS_BASE_ADDRESS+4)) 11 | #define BIT_BAND_ALIAS_ADDRESS_3 *((volatile unsigned long *)(BIT_BAND_ALIAS_BASE_ADDRESS+8)) 12 | 13 | 14 | int main(void) 15 | { 16 | uint32_t val; 17 | BIT_BAND_REGION_MEM_ADDR_1 = 0xA0; 18 | BIT_BAND_ALIAS_ADDRESS_1 = 0x01; 19 | 20 | BIT_BAND_ALIAS_ADDRESS_2 = 0x01; 21 | BIT_BAND_ALIAS_ADDRESS_3= 0x01; 22 | 23 | val = BIT_BAND_REGION_MEM_ADDR_1; 24 | return 0; 25 | } --------------------------------------------------------------------------------