EK-TM4C129EXL: C and assembly mixture

Part Number: EK-TM4C129EXL

Hi Team,

Posting on behalf of our customer.

 I am creating my own RTOS for my microcontroller.  To ensure correctness, I am mixing both assembly and C.  I have looked online and have found that there are some flags I can setup in the setup.  I am just not sure though if what I did is correct.  Could I please have someone check it out to ensure correct implementation of C and assembly?

MATRIX7878/Simple-RTOS

Regards,

Danilo

  • Hi Danilo,

    The way you are calling the assembly functions appears correct. My only concern is with the RunPt variable you are referencing. Please, ensure you are following the guidelines documented here for interfacing Assembly and C code: https://software-dl.ti.com/codegen/docs/tiarmclang/compiler_tools_user_guide/compiler_manual/runtime_environment/interfacing-c-and-c-with-assembly-language-stdz0544217.html

    Thanks,

    -Eric Rentschler

  • Hello,

            This is the original creator of the question.  The only thing I noticed is that on line 64 of my .asm file, I had .word instead of .field.  Is that what you meant?  If not, I am not sure what else there could be.  It all looks the same to me.

    Thank you

  • Hi Drew,

    Is there a specific error you are seeing?

    Thanks,

    -Eric Rentschler

  • Hi Eric,

            No, there are no syntax errors, but there is a runtime error when I call my startOS() function on line 137.  My interrupt assembly functions appear to work well, but when I try to start my OS, I get a fault ISR.  I do not know if I am not seeing the interrupt assembly code not work correctly (as debugging never jumps to the assembly file), or if the attempt I have with the RunPt is still giving me a headache.

    Thank you

  • Hi Drew,

    Is there a specific call inside of the start OS routine that is causing the fault ISR?

    Thanks,

    -Eric Rentschler

  • Hi Eric,

           Unfortunately, I cannot give a good answer for this.  When I get to line 137, I try to step into it, but CCS does not jump to the .asm file.  Ergo, I cannot say what line in the assembly file is causing a problem.  All I can say for certain is that assembly function is the last thing I can jump into before the program seems to crash and all I can do is pause it to see I have a fault ISR.  Is there a way to jump into the assembly file from the C file when I am at the startOS function?

    Thank you

  • Hello,

             I hope you are well; I was hoping to know if you had any other ideas for me.  I would like to get my RTOS complete but need to be able to figure out where my fault is.

    Thank you

  • Hi Drew,

    Sorry for the delay. It seems like the fault may be calling the startOs function itself. I would suggest you simplify the startOS function and ensure that the assembly code it properly linked and doesn't cause any issues.

    Thanks,

    -Eric Rentschler

  • Hello,

              Is there a way to debug into the assembly file?  That way I can see exactly which line is throwing a fault?  I am just not sure how to ensure proper linkage.  I can do assembly only programs and C only programs but combining them is where I want to ensure I am doing it right.

    Thank you

  • I don't have the infrastructure to try your code  in particular but:

    1) I have used instruction-level breakpoints and instruction-step with CCS. These should work even if (C-level) step-into doesn't work.

    2) Have you seen the debugging document SPMA043 (here)? The Stellaris were Cortex-M3 as I recall, but most of the information should apply to the Cortex-M4.

    3) At the Hard Fault, SP points to [R0-R3, R12, LR, PC, xPSR]. I always start by looking at that 7th word to see where the exception happened.

  • I used breakpoints in my assembly and I see that the assembly file completes and then goes back to the C file.  It seems as though the FaultISR happens after the C program completes?  Or (as has happened in the past) when I step, it fixes whatever timing problem and then the code works.

    No, I have no seen that document before, but followed the instructions.  It says that the error is at 0xE000EDF8.  Which from what I can find, is not an actual offset for the SYSCTL register.

    When looking at the hard fault, SP shows me:

    I do have a 0xFFFFFFF8 (no symbols defined) issue in the debug window.  I do not know if my code is incomplete (it seems as though only one of my threads is running), or if there is something else wrong with my code.  I hope this helps give a bigger picture of what I am facing.  Thank you.

  • I don't see a reference to 0xE000EDF8 in SPMA043. Architecture Reference Manual (DDI0403E) Table C1-10 says this is the DCRDR, which probably isn't very useful here. 

    It does recommend looking at  0xE000ED28, which is SCB->CFSR [Ref A-R-M Sec B3.2.15]; that might have something useful. 

    My first guess is that this started out as a Usage Fault. The saved registers seem to say that PC=0, i.e. you somehow branched to location 0 (invalid instruction), perhaps due to something wrong in the stack.  

    What is at *LR (=0x2450)? This would tell you where the most recent call was made, which narrows things down.

    More generally, do you ever reach task0()?

  • For the TM4C, 0xE000E000 is the SYSCTL register, however, there is no 0xDF8 offset, so why it is saying that I'm not sure.  Perhaps it means the DCRDR, but I cannot be certain.

    According to the address, I have a usage error 0x00020000, which is "Instruction executed with invalid EPSR.T or EPSR.IT field."  It seems then that there is a problem with how I am enabling and disabling interrupts for the system.  I may have that wrong.  Be nice if CCS was more descriptive.

    It seems like it is a usage fault.  Perhaps my code is then incomplete for the design.

    The link register is at 0xFFFFFFF8, so far outside of the memory region.  So somewhere it falls apart.  Since it seems to break after it calls task2(), my threading might be wrong.

    Yes, my task0_init() does get called.  The problem happens after OS_Launch is called.  It should loop through all the threads I made.  I am not sure if it is my interrupts then, or something else.

    I do appreciate your help, this is my first RTOS and it is an interesting learning curve.

  • The stacked xPSR is =0, so the T bit is 0, which would also generate a Usage Fault. This can result from a BX to a register with the low-bit =0.

    I was asking about task0(), which is the first task that executes out of OS_Launch(). I suggest a breakpoint there.

    The 0xFFFFFFF8 looks like an EXC_RETURN (though the ones I remember have the low-order bit set); a return using one of those LR values performs (in effect) an RTI. [Ref A-R-M Sec B1.5.8]

    [Edit: Added reference]

  • The only bx I am using is to the link register.  Could there be a problem with how I am calling it in startOS?  I use it in other assembly functions, but it does not seem to have a problem there.  Maybe it does not like that I am trying to enable interrupts on the line above without them being disabled?

    Oh my bad.  No, task0() never gets executed.  After the OS starts up, it goes straight to task2().

    CCS says 0xFFFFFFF8 (no symbols defined).  Every other time I have had that error, something in my code is not complete.  I am not sure though what it is in this code.  It seems like the C + assembly is working, but something is certainly strange.

  • Having an EXC_RETURN in LR is completely expected after a Hard Fault. It's the stacked PC and to some extent the stacked LR that are interesting.

    The fact that task2 ran first may also be a clue.

    Does each failure look the same?

    If my experience is an indicator at some point you'll be doing a bunch of instruction-stepping. By then you'll want to have narrowed the scope. What is at 0x2450?

  • It seems like the first thread I have set up will run twice and then the code fails.

    Seems like the threading is unable to advance the pointer to the next thread.  If I switched task2 with task0, then task0 runs twice and then breaks.  I would say yes then that every failure looks the same.

    I step through the code and then the problem comes it seems from the threads not switching.  Though I cannot be certain that that is the issue.

    At 0x2450, I am at 0x46C0BD08 (nowhere).  The data sheet for the TM4C does not have a register for 0x46XXXXXX.  It is an empty memory space.  Do you see some escape sequence in my code forcing the random jump?

  • I think 0x2450 is in (code) flash. What does the .map file say?

  • I do not see 0x2450 in the .map file.  Am I missing it?

    ******************************************************************************
                      TI ARM Linker PC v20.2.7                     
    ******************************************************************************
    >> Linked Fri Jan 30 12:09:07 2026
    
    OUTPUT FILE NAME:   <RTOS.out>
    ENTRY POINT SYMBOL: "_c_int00_noargs"  address: 0000286d
    
    
    MEMORY CONFIGURATION
    
             name            origin    length      used     unused   attr    fill
    ----------------------  --------  ---------  --------  --------  ----  --------
      FLASH                 00000000   00100000  00002e81  000fd17f  R  X
      SRAM                  20000000   00040000  000008c2  0003f73e  RW X
    
    
    SEGMENT ALLOCATION MAP
    
    run origin  load origin   length   init length attrs members
    ----------  ----------- ---------- ----------- ----- -------
    00000000    00000000    00002e88   00002e88    r-x
      00000000    00000000    00000208   00000208    r-- .intvecs
      00000208    00000208    000026c6   000026c6    r-x .text
      000028ce    000028ce    0000057b   0000057b    r-- .const
      00002e50    00002e50    00000038   00000038    r-- .cinit
    20000000    20000000    000008c5   00000000    rw-
      20000000    20000000    000006a5   00000000    rw- .bss
      200006a8    200006a8    00000200   00000000    rw- .stack
      200008a8    200008a8    0000001d   00000000    rw- .data
    
    
    SECTION ALLOCATION MAP
    
     output                                  attributes/
    section   page    origin      length       input sections
    --------  ----  ----------  ----------   ----------------
    .intvecs   0    00000000    00000208     
                      00000000    00000208     tm4c129encpdt_startup_ccs.obj (.intvecs)
    
    .text      0    00000208    000026c6     
                      00000208    0000243c     main.obj (.text)
                      00002644    0000009c     rtsv7M4_T_le_v4SPD16_eabi.lib : memcpy_t2.asm.obj (.text)
                      000026e0    0000007a                                   : memset_t2.asm.obj (.text)
                      0000275a    00000068                                   : copy_decompress_lzss.c.obj (.text:decompress:lzss:__TI_decompress_lzss)
                      000027c2    00000002     --HOLE-- [fill = 0]
                      000027c4    00000064     rtos.obj (.text)
                      00002828    00000044     rtsv7M4_T_le_v4SPD16_eabi.lib : autoinit.c.obj (.text:__TI_auto_init_nobinit_nopinit:__TI_auto_init_nobinit_nopinit)
                      0000286c    00000034                                   : boot_cortex_m.c.obj (.text:_c_int00_noargs:_c_int00_noargs)
                      000028a0    0000000e                                   : copy_decompress_none.c.obj (.text:decompress:none:__TI_decompress_none)
                      000028ae    0000000c                                   : copy_zero_init.c.obj (.text:decompress:ZI:__TI_zero_init)
                      000028ba    0000000c     tm4c129encpdt_startup_ccs.obj (.text)
                      000028c6    00000004     rtsv7M4_T_le_v4SPD16_eabi.lib : pre_init.c.obj (.text:_system_pre_init)
                      000028ca    00000004                                   : exit.c.obj (.text:abort:abort)
    
    .const     0    000028ce    0000057b     
                      000028ce    000004fb     main.obj (.const:.string:Font)
                      00002dc9    0000003b     main.obj (.const:.string:Scmd1)
                      00002e04    0000002b     main.obj (.const:.string:Scmd3)
                      00002e2f    0000000d     main.obj (.const:.string:Scmd2green)
                      00002e3c    0000000d     main.obj (.const:.string:Scmd2red)
    
    .cinit     0    00002e50    00000038     
                      00002e50    00000014     (.cinit..data.load) [load image, compression = lzss]
                      00002e64    0000000c     (__TI_handler_table)
                      00002e70    00000008     (.cinit..bss.load) [load image, compression = zero_init]
                      00002e78    00000010     (__TI_cinit_table)
    
    .init_array 
    *          0    00000000    00000000     UNINITIALIZED
    
    .bss       0    20000000    000006a5     UNINITIALIZED
                      20000000    00000640     (.common:stacks)
                      20000640    00000020     (.common:tcbs)
                      20000660    0000000c     (.common:Message)
                      2000066c    00000004     main.obj (.bss)
                      20000670    00000004     (.common:Messageindex)
                      20000674    00000004     (.common:RunPt)
                      20000678    00000004     (.common:TimeIndex)
                      2000067c    00000004     (.common:X)
                      20000680    00000004     (.common:Ymax)
                      20000684    00000004     (.common:Ymin)
                      20000688    00000004     (.common:Yrange)
                      2000068c    00000004     (.common:mag)
                      20000690    00000004     (.common:mail)
                      20000694    00000004     (.common:time)
                      20000698    00000002     (.common:AccX)
                      2000069a    00000002     (.common:AccY)
                      2000069c    00000002     (.common:AccZ)
                      2000069e    00000002     (.common:PlotBGColor)
                      200006a0    00000002     (.common:joyX)
                      200006a2    00000002     (.common:joyY)
                      200006a4    00000001     (.common:push)
    
    .data      0    200008a8    0000001d     UNINITIALIZED
                      200008a8    0000001d     main.obj (.data)
    
    .stack     0    200006a8    00000200     UNINITIALIZED
                      200006a8    00000004     rtsv7M4_T_le_v4SPD16_eabi.lib : boot_cortex_m.c.obj (.stack)
                      200006ac    000001fc     --HOLE--
    
    __llvm_prf_cnts 
    *          0    20000000    00000000     UNINITIALIZED
    
    MODULE SUMMARY
    
           Module                          code   ro data   rw data
           ------                          ----   -------   -------
        .\
           main.obj                        9276   1403      1730   
           tm4c129encpdt_startup_ccs.obj   12     520       0      
           rtos.obj                        100    0         0      
        +--+-------------------------------+------+---------+---------+
           Total:                          9388   1923      1730   
                                                                   
        C:\ti\ccs1281\ccs\tools\compiler\ti-cgt-arm_20.2.7.LTS\lib\rtsv7M4_T_le_v4SPD16_eabi.lib
           memcpy_t2.asm.obj               156    0         0      
           memset_t2.asm.obj               122    0         0      
           copy_decompress_lzss.c.obj      104    0         0      
           autoinit.c.obj                  68     0         0      
           boot_cortex_m.c.obj             52     0         0      
           copy_decompress_none.c.obj      14     0         0      
           copy_zero_init.c.obj            12     0         0      
           exit.c.obj                      4      0         0      
           pre_init.c.obj                  4      0         0      
        +--+-------------------------------+------+---------+---------+
           Total:                          536    0         0      
                                                                   
           Stack:                          0      0         512    
           Linker Generated:               0      56        0      
        +--+-------------------------------+------+---------+---------+
           Grand Total:                    9924   1979      2242   
    
    
    LINKER GENERATED COPY TABLES
    
    __TI_cinit_table @ 00002e78 records: 2, size/record: 8, table size: 16
    	.data: load addr=00002e50, load size=00000014 bytes, run addr=200008a8, run size=0000001d bytes, compression=lzss
    	.bss: load addr=00002e70, load size=00000008 bytes, run addr=20000000, run size=000006a5 bytes, compression=zero_init
    
    
    LINKER GENERATED HANDLER TABLE
    
    __TI_handler_table @ 00002e64 records: 3, size/record: 4, table size: 12
    	index: 0, handler: __TI_decompress_lzss
    	index: 1, handler: __TI_decompress_none
    	index: 2, handler: __TI_zero_init
    
    
    GLOBAL SYMBOLS: SORTED ALPHABETICALLY BY Name 
    
    address   name                          
    -------   ----                          
    20000698  AccX                          
    2000069a  AccY                          
    2000069c  AccZ                          
    000028cb  C$$EXIT                       
    000003cf  DCinit                        
    20000660  Message                       
    20000670  Messageindex                  
    000020e1  OS_AddThreads                 
    00002155  OS_Launch                     
    00001fcd  OS_init                       
    0000218b  OS_initSem                    
    00002225  OS_mailInit                   
    0000225b  OS_mailRecv                   
    0000223d  OS_mailSend                   
    000021fd  OS_sig                        
    000021a9  OS_wait                       
    2000069e  PlotBGColor                   
    200008c4  Plotstate                     
    00000963  RGBInit                       
    000028bb  ResetISR                      
    20000674  RunPt                         
    00001fd9  SetInitialStack               
    200008b0  StTextColor                   
    200008a8  StX                           
    200008ac  StY                           
    20000678  TimeIndex                     
    2000067c  X                             
    20000680  Ymax                          
    20000684  Ymin                          
    20000688  Yrange                        
    200008a8  __STACK_END                   
    00000200  __STACK_SIZE                  
    200008a8  __STACK_TOP                   
    00002e78  __TI_CINIT_Base               
    00002e88  __TI_CINIT_Limit              
    00002e64  __TI_Handler_Table_Base       
    00002e70  __TI_Handler_Table_Limit      
    00002829  __TI_auto_init_nobinit_nopinit
    0000275b  __TI_decompress_lzss          
    000028a1  __TI_decompress_none          
    ffffffff  __TI_pprof_out_hndl           
    ffffffff  __TI_prof_data_size           
    ffffffff  __TI_prof_data_start          
    00000000  __TI_static_base__            
    000028af  __TI_zero_init                
    000026e1  __aeabi_memclr                
    000026e1  __aeabi_memclr4               
    000026e1  __aeabi_memclr8               
    00002645  __aeabi_memcpy                
    00002645  __aeabi_memcpy4               
    00002645  __aeabi_memcpy8               
    000026e3  __aeabi_memset                
    000026e3  __aeabi_memset4               
    000026e3  __aeabi_memset8               
    ffffffff  __binit__                     
    ffffffff  __c_args__                    
    UNDEFED   __mpu_init                    
    200006a8  __stack                       
    20000000  __start___llvm_prf_cnts       
    20000000  __stop___llvm_prf_cnts        
    0000286d  _c_int00_noargs               
    UNDEFED   _system_post_cinit            
    000028c7  _system_pre_init              
    000028cb  abort                         
    00000223  accIn                         
    00000263  accInit                       
    ffffffff  binit                         
    000002e5  buzzerInit                    
    000012a1  color565                      
    000027c5  disInt                        
    00001bbd  drawAxes                      
    00001301  drawBMP                       
    00001503  drawChar                      
    000011e9  drawHor                       
    000010a1  drawPixel                     
    00001681  drawString                    
    00001119  drawVert                      
    000027c9  enInt                         
    000027d5  endCrit                       
    00001701  fillMessage                   
    00001743  fillMessage4                  
    000017b5  fillMessage5                  
    00000bf1  fillScreen                    
    00000000  g_pfnVectors                  
    00001035  invDisp                       
    00000459  joyIn                         
    00000497  joyInit                       
    200006a0  joyX                          
    200006a2  joyY                          
    200008b8  lightBusy                     
    000008f9  lightInit                     
    00000859  lightInput                    
    000008b1  lightSenseEnd                 
    00000889  lightSenseStart               
    2000068c  mag                           
    20000690  mail                          
    200008bc  mailData                      
    0000258d  main                          
    00002645  memcpy                        
    000026e9  memset                        
    0000194d  outUDec                       
    000019c7  outUDec4                      
    00001a59  outUDec5                      
    00001ad9  outUFix2_10                   
    00001b3f  outUHex2                      
    00001e91  pll                           
    00001dcf  plotClear                     
    00001da1  plotInc                       
    00001e2b  plotNext                      
    00001e45  plotNextErase                 
    00001d2d  plotPoint                     
    200006a4  push                          
    200008c0  redraw                        
    0000217f  scheduler                     
    00000b95  setCursor                     
    00000f69  setRot                        
    000022a1  sqrt32                        
    20000000  stacks                        
    000027cd  startCrit                     
    00002805  startOS                       
    000012d5  swapColor                     
    000027dd  sysHand                       
    00000209  sysctlInit                    
    00002339  task0                         
    000022f1  task0_Init                    
    000023f1  task1                         
    00002389  task1_Init                    
    00002441  task2                         
    00002465  task3                         
    00002477  task4                         
    00002521  task5                         
    20000640  tcbs                          
    20000694  time                          
    00001f2b  toggleInit                    
    
    
    GLOBAL SYMBOLS: SORTED BY Symbol Address 
    
    address   name                          
    -------   ----                          
    00000000  __TI_static_base__            
    00000000  g_pfnVectors                  
    00000200  __STACK_SIZE                  
    00000209  sysctlInit                    
    00000223  accIn                         
    00000263  accInit                       
    000002e5  buzzerInit                    
    000003cf  DCinit                        
    00000459  joyIn                         
    00000497  joyInit                       
    00000859  lightInput                    
    00000889  lightSenseStart               
    000008b1  lightSenseEnd                 
    000008f9  lightInit                     
    00000963  RGBInit                       
    00000b95  setCursor                     
    00000bf1  fillScreen                    
    00000f69  setRot                        
    00001035  invDisp                       
    000010a1  drawPixel                     
    00001119  drawVert                      
    000011e9  drawHor                       
    000012a1  color565                      
    000012d5  swapColor                     
    00001301  drawBMP                       
    00001503  drawChar                      
    00001681  drawString                    
    00001701  fillMessage                   
    00001743  fillMessage4                  
    000017b5  fillMessage5                  
    0000194d  outUDec                       
    000019c7  outUDec4                      
    00001a59  outUDec5                      
    00001ad9  outUFix2_10                   
    00001b3f  outUHex2                      
    00001bbd  drawAxes                      
    00001d2d  plotPoint                     
    00001da1  plotInc                       
    00001dcf  plotClear                     
    00001e2b  plotNext                      
    00001e45  plotNextErase                 
    00001e91  pll                           
    00001f2b  toggleInit                    
    00001fcd  OS_init                       
    00001fd9  SetInitialStack               
    000020e1  OS_AddThreads                 
    00002155  OS_Launch                     
    0000217f  scheduler                     
    0000218b  OS_initSem                    
    000021a9  OS_wait                       
    000021fd  OS_sig                        
    00002225  OS_mailInit                   
    0000223d  OS_mailSend                   
    0000225b  OS_mailRecv                   
    000022a1  sqrt32                        
    000022f1  task0_Init                    
    00002339  task0                         
    00002389  task1_Init                    
    000023f1  task1                         
    00002441  task2                         
    00002465  task3                         
    00002477  task4                         
    00002521  task5                         
    0000258d  main                          
    00002645  __aeabi_memcpy                
    00002645  __aeabi_memcpy4               
    00002645  __aeabi_memcpy8               
    00002645  memcpy                        
    000026e1  __aeabi_memclr                
    000026e1  __aeabi_memclr4               
    000026e1  __aeabi_memclr8               
    000026e3  __aeabi_memset                
    000026e3  __aeabi_memset4               
    000026e3  __aeabi_memset8               
    000026e9  memset                        
    0000275b  __TI_decompress_lzss          
    000027c5  disInt                        
    000027c9  enInt                         
    000027cd  startCrit                     
    000027d5  endCrit                       
    000027dd  sysHand                       
    00002805  startOS                       
    00002829  __TI_auto_init_nobinit_nopinit
    0000286d  _c_int00_noargs               
    000028a1  __TI_decompress_none          
    000028af  __TI_zero_init                
    000028bb  ResetISR                      
    000028c7  _system_pre_init              
    000028cb  C$$EXIT                       
    000028cb  abort                         
    00002e64  __TI_Handler_Table_Base       
    00002e70  __TI_Handler_Table_Limit      
    00002e78  __TI_CINIT_Base               
    00002e88  __TI_CINIT_Limit              
    20000000  __start___llvm_prf_cnts       
    20000000  __stop___llvm_prf_cnts        
    20000000  stacks                        
    20000640  tcbs                          
    20000660  Message                       
    20000670  Messageindex                  
    20000674  RunPt                         
    20000678  TimeIndex                     
    2000067c  X                             
    20000680  Ymax                          
    20000684  Ymin                          
    20000688  Yrange                        
    2000068c  mag                           
    20000690  mail                          
    20000694  time                          
    20000698  AccX                          
    2000069a  AccY                          
    2000069c  AccZ                          
    2000069e  PlotBGColor                   
    200006a0  joyX                          
    200006a2  joyY                          
    200006a4  push                          
    200006a8  __stack                       
    200008a8  StX                           
    200008a8  __STACK_END                   
    200008a8  __STACK_TOP                   
    200008ac  StY                           
    200008b0  StTextColor                   
    200008b8  lightBusy                     
    200008bc  mailData                      
    200008c0  redraw                        
    200008c4  Plotstate                     
    ffffffff  __TI_pprof_out_hndl           
    ffffffff  __TI_prof_data_size           
    ffffffff  __TI_prof_data_start          
    ffffffff  __binit__                     
    ffffffff  __c_args__                    
    ffffffff  binit                         
    UNDEFED   __mpu_init                    
    UNDEFED   _system_post_cinit            
    
    [134 symbols]
    

  • It looks like 0x2450 is in task2 (based at 0x2441).

    You can also type it into the Disassembly view to get more detail.

  • Ah, that is a good catch, I was thinking too explicitly.  It seems like the problem is trying to pop R3 and PC and move to the next PC.

    Are my SetInitialStack and/or the OS_AddThreads functions not correct?  Those are handling the stack.  I will review my code, again, but if popping R3 and PC is a problem, then how I am handling the stack might be wrong.

  • What's in the stack when that return happens? At least this gives you a place to start.

    More generally: What did you intend to happen when a taskN function returns? In some RTOSes task functions never return.

  • In the stack there is 

    But is this what you mean by stack?  It then goes to 0x00000000 before the fault.  So it runs to task2(), repeats then faults:

    I expect that when one task finishes, the next task starts.  It should be a looping thread scenario.  Something like task2() -> task3() -> task4() -> task5() -> task2() ....  You are right, I never expect it to return.  I wonder if my scheduling is wrong since I loop task2().

  • From your description (successive calls to taskN()) it sounds as though you actually Do expect each function to return ("run to completion" model), and that's what they're doing.

    This is fine, except that StartOS gets to (e.g.) task2() using a "BX LR", which gives the target function nothing to return to. (More to the point, it provides a return point in LR which is the top of the task2() function, so it gets nowhere.)

    I encourage you to try breakpoint-ing at 0x2450 and instruction-stepping through the return to see what it's doing.

    Supposing I'm guessing correctly about what you had in mind, you might get somewhere by (1) invoking taskN() using "BLX LR" (so it returns Right There) (2) calling "scheduler", then (3) branching back to the top of StartOS() to load the stuff from the updated TCB.

    [I don't have my materials here, so I'm working from memory, but I think that's about right.]

  • Yes, each thread should return, but the loop never end.

    What I am expecting is the systick handling assembly function to do the transitions between threads.

    I hit 0x2450 twice.  That is the end of the task2() function.  After the second one, then it breaks.  As can be seen in this picture, it sees that address twice.

    I stepped through like you said and I hit 0x2450 twice.  So it seems like my systick interrupt handler is not working.  I wonder if I am not connecting it correctly.  I run 0x2440 through 0x2450 twice, then break.

    I changed to blx lr and that made it so task2() does not run twice, but then breaks immediately after it completes.  I have a fault at that line in the assembly file:

    What do you mean call scheduler?  In task2()? in the assembly functions?  Go back to the start of the OS?  You think it will change the pointer address?

    Here is the entire project in case it will help you see if I am not calling something right.  Thank you, I do appreciate all your help.

    6278.RTOS.zip

  • As coded, the taskN() functions all return. If they run within 120K clocks (quite probable) the SysTick won't matter.

    If you intend for them not to return, you need to make sure they don't, e.g. with a "forever" ("while(1)") loop. 

    On the other hand, there's nothing wrong with "run to completion". It looks like you did step (1) above but not (2) or (3).

    [Edit: The .zip you posted still seems to be missing pll.h and BSP.h.]

  • I think I figured it out.  I tried switching my threads around and noticed that it did behave differently.  I did need a while loop in each thread, that way the systick handler will execute correctly.  I had several timing violations before, hence the faultISR.  This is the full code working right now.  I also expanded my stack just to be on the safe side.  Just playing devils advocate, I do not want to be playing with a false positive.  Does this look like it's a red herring?  It is working, but it's not correct?

    0636.RTOS.zip

  • I'm not really in a position to review all of this code.

    Does the program (overall) do what you intended? Have you seen a (successful) task switch?

  • I understand, I do remember you saying you did not have this system.

    Yes, it does what I intend and the tasks do switch, so I guess everything is working, I just didn't want to be misled by this design.  Thank you for all your help, I think my problem is solved.