Announcement

Collapse
No announcement yet.

CSL '0401' Program Binary Disassembly Notes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MpowerE36
    replied
    Here all my knowledge about the rf calculation of the BMW CSL engine. I hope this will be appreciated for its true value​. You will have to do a bit of translation because I wrote it in French in the past but I am sure that will not be a problem​.
    Attached Files

    Leave a comment:


  • karter16
    replied
    Originally posted by MpowerE36 View Post
    I did this reverse engineering work long time ago. I can give you the solution if you are insterested.
    That would be awesome - would you be willing for it to be shared with the community? as that's my ultimate aim is to have information available for everyone.


    Sent from my iPhone using Tapatalk

    Leave a comment:


  • ac427
    replied
    Originally posted by MpowerE36 View Post
    I did this reverse work long time ago. I can give you the solution if you are insterested.
    It would be interesting to see it.

    Leave a comment:


  • MpowerE36
    replied
    I did this reverse engineering work long time ago. I can give you the solution if you are insterested.
    Last edited by MpowerE36; 02-22-2025, 07:11 AM.

    Leave a comment:


  • karter16
    replied
    I think I might still be wrong (although I'm getting tired and that's never a good time to figure complicated things out) - Working it through some more I now don't think the adjusted RF value (up to a max of 2.5%) actually does continue to ramp towards RF from map pressure because the base RF from AlphaN is reset every time round the function, it therefore doesn't matter how far apart RF and RF from MAP are because the final RF value is only ever close to the RF from MAP value by 2.5%. It's now looking to me like the 2.5% limit is indeed correct...

    I'll come back to this with fresh eyes later in case I'm now missing something that I wasn't earlier.

    Leave a comment:


  • Slideways
    replied
    Nice work!

    I believe that terra , SliM3 , and olza had some ideas of how the MAP sensor worked in the old MSS54/HP comprehensive thread.

    This is the thread I made a while ago (https://nam3forum.com/forums/forum/s...ensor-function) and the images from the E92 and CSL technical document:

    Click image for larger version  Name:	fetch?id=8781&d=1586469249.png Views:	0 Size:	449.4 KB ID:	295271Click image for larger version  Name:	fetch?id=8782&d=1586469280.png Views:	0 Size:	597.7 KB ID:	295272

    IIRC, Terra said that BMW simplified the description of how the MAP sensor worked (mainly for the CSL).

    Did BMW use a MAP sensor before the S54 or was that the first engine with it? (Maybe the first because previous DMEs were not as advanced?)
    Last edited by Slideways; 02-21-2025, 10:16 PM.

    Leave a comment:


  • karter16
    replied
    NOTE: The post below shows point-in-time understanding of this function. For a correct and complete disassembly of this function with accurate comments please see post #57

    Ok here's the next one - this is Function 0x00021f2c - I've called this "CSL_RF_Calculate_Pressure_adjustment" and it runs in the 10ms task and establishes the 2.5 percentage-point limited rf_pressure_adjustment value stored in 0x00ffeed8.

    It uses the difference between p_umg (ambient pressure) and MAP sensor pressure to lookup a multiplicative factor. This factor is then applied to the difference between rf_pressure_adjusted and RF. The result is then limited to the 2.5 percentage point variance and stored in rf_pressure_adjustment which in turn is used in CSL_Calculate_RF_Final above.

    Click image for larger version  Name:	Screenshot 2025-02-22 at 5.08.23 PM.png Views:	54 Size:	210.9 KB ID:	295264
    Click image for larger version  Name:	Screenshot 2025-02-22 at 5.08.34 PM.png Views:	55 Size:	234.7 KB ID:	295265
    Last edited by karter16; 02-23-2025, 10:38 PM.

    Leave a comment:


  • karter16
    replied
    Okay - Here's the start of the disassembly to try to explain this. It's going to be too complicated for me to try to explain all in one go, so I'm going to start with the end (the final RF calculation) and then step backwards to the individual inputs to explain. Hopefully this makes sense.

    The final RF (Relative Fill) value is calculated in the master in the function at 0x000218d0 (this is the function people will have seen referenced before when discussing this topic). For internal (to my brain) sanity purposes I have chosen to name this function "CSL_Calculate_RF_Final". This function runs in the segment task which means it runs every 120 crankshaft degrees of rotation (so very, very frequently). In addition to calculating RF this function actually also calculates RF5 (RF divided by 5 - legacy from earlier software versions where memory space was at a premium), ML (air mass), TL (load signal), and DAM (Delta Air Mass).

    Here's the disassembly - you'll have to suffer through my non-consistent naming conventions sorry. The disassembly also tends to result in more verbose and harder to read C-code. Eventually I'll make a tidied up version of this code which will be easier to read, but for now this is what we have - I'll let you read through it - my explanation is below:

    Click image for larger version

Name:	Screenshot 2025-02-22 at 12.52.25 PM.png
Views:	133
Size:	191.4 KB
ID:	295219
    Click image for larger version

Name:	Screenshot 2025-02-22 at 12.52.37 PM.png
Views:	117
Size:	173.5 KB
ID:	295220

    So essentially this function runs 6 times per cycle (720 degrees of crankshaft rotation). The key steps of the function are as below:

    1: Calculate a value for rf based on the calculated cylinder pressure (I've called this cyl_charge_pressure, although I'm not completely sure this is the best way to describe it) and a factor that describes the normal mass of air in the cylinder.
    2: Next we check to make sure that the engine is not in the process of starting. If it is then we use const values for RF and ML, but if it's not we carry on.
    3: Next we check a parameter I've called K_RF_Calc_Config as this is a config byte which is used to define how this function operates. The way that it's set by default means that we carry on to line 29.
    4: We take the rf value we looked up against the AlphaN table (this is the well-known 20x24 "CSL AlphaN Main" map) and adjust it by a modifying factor based on TABG.
    5: We then do some scaling adjustments and set this to be our current RF value.
    6: We then check K_RF_Calc_Config again and based on the default value we proceed to line 36
    7: We then take a value I've labelled as "rf_pressure_adjustment" this is calculated in a separate function and is where the "2.5% limit" comes in. the value returned is the difference between RF and rf_pressure_adjusted (which we calculated on line 15) and limited to a max difference of 2.5 percentage points.
    8: We then modify RF by this rf_pressure_adjustment.


    And these steps pretty much explain why it has been thought that RF is adjusted by the MAP pressure up to 2.5%.

    So why isn't it this simple? Let's keep working our way down.

    9: on line 61 we calculate ML based on the RF value from step 8, the function then does a bunch of other stuff which is important for other things and then returns.

    Okay cool, but how does this help? Next time the function runs the initial RF we take is "reset" to the AlphaN_TABG adjusted value, then has the "2.5%" adjustment applied again, but that's just the same thing as we had before isn't it? Sure as RPM and aq_rel (Relative Opening) change, and TABG changes the RF value will change, but how do we close the gap between that RF and the RF calculated from the MAP sensor?

    The answer is in line 15.

    Code:
    rf_pressure_adjusted = (ushort)(((uint)cyl_mass_factor * (int)cyl_charge_pressure?) / 0xffff);
    The function that calculates cyl_charge_pressure 0x000216e2, among many other things, takes the variable at 0x00ffef22 and uses it to calculate the new cyl_charge_pressure. What's in 0x00ffef22? It's a pressure related value which takes, as one of its inputs, ML (the ML we just calculated based on the RF adjusted by MAP pressure we just calculated).

    I'll share these other functions in subsequent posts as it's a lot to lay out and take in, but I believe that this is how RF is ramped to the MAP-adjusted RF.

    The above task and the cyl_charge_pressure tasks run in the segment task, so they are constantly adjusting RF and ML towards the 2.5% limited target RF.

    Every 10ms the 10ms task fires and runs the function that recalculates the rf_pressure_adjustment (which is the 2.5% limited one). When it runs it's now comparing the newest RF against the MAP-based RF target (so in stable state the two values are closer than they were 10ms ago). If they're still more than 2.5 percentage points apart rf_pressure_adjustment will stay at 2.5 percent, if they're close it will scale down until they are the same.

    This is why I retracted my statement about a limit of 2.5 percentage points per 10ms, as given the ramping is driven from the segment task, I can't be exactly sure how far it will get in the space of 10ms before it's re-evaluated. the number of times the segment task fires in 10ms varies depending on engine speed.

    I'll share the details of the other functions I reference later (I have other things to do in my day also :-)), but hopefully this is the start of bringing clarity to this.

    (Also if you think I've missed something/made a mistake/etc. please shout out! The only way we all learn is to search for the right answer together)

    Leave a comment:


  • karter16
    replied
    Update - I've highlighted in red two statements in my initial post of the MAP sensor which are incorrect. There is another layer of complexity which I'd missed, the statement about 2.5%/10ms is incorrect as additionally the calculation of ml based on the modified RF value then influences the calculation of pressure and the resultant pressure adjusted RF. I need some more time but wanted to update here ASAP to correct my previous statement.

    Also apologies for the incorrect/overly simplified statement in my initial post. I got excited and posted - I should have taken more time and found this complexity first before presenting the information. I'm trying to reduce confusion on this topic not add to it 😔

    Edit: From what I'm seeing so far I believe it works in approximately the same way as I describe (just achieved slightly more indirectly in that the adjusted RF is used to calculate the new ML value which in turn is used to calculate the new cylinder pressure which in turn is used to calculate the new pressure adjusted RF which in turn has the latest MAP sensor reading applied to it), I just now have more code to wade through to make certain I'm right.
    Last edited by karter16; 02-21-2025, 12:42 PM.

    Leave a comment:


  • Bry5on
    replied
    Hell yes, thank you for breaking it down so clearly and cleanly. Those that have the MAP sensor next to the brake booster will have some additional smoothing from the hose acting as an accumulator/manifold too. Can’t tell you if this is a good or bad thing, but perhaps increasing that max above 2.5%/10ms would be worth the experiment.

    Leave a comment:


  • karter16
    replied
    Originally posted by S54B32 View Post

    I'm VERY happy that finally someone spends the time to bust this myth. Thank you for contributing this to the community!
    Just for all the skeptical persons out there, could you please share some screenshots of the relevant parts of the disassambly to make your findings about this bulletproof?
    Absolutely - It's a bit of a tangle and I posted pretty much as soon as I'd got it all figured out. I'm just tidying up my comments, etc. and will try to lay it out as clearly as possible. There's a few different functions in the mix so will do my best!

    Leave a comment:


  • ac427
    replied
    Originally posted by karter16 View Post
    I've been looking into the calculation of RF (relative fill) and how the MAP sensor etc. inputs into that, as it still seems to be an area of debate.

    From what I've seen so far the following misconceptions that float around can be addressed:

    Misconception 1: "The MAP sensor isn't used in normal use, the CSL runs pure AlphaN"
    This is absolutely not the case, this may be due to a misinterpretation around how the status byte at 0x00ff807e is calculated, however in the happy path flow of the software the MAP sensor input is absolutely used (the difference between manifold pressure and ambient pressure is used to calculate an RF adjustment value). The amount of input it has appears to be limited to part throttle applications in low and mid-range RPM (hello drivability), but to say that the CSL runs pure AlphaN just isn't true (sorry AlphaN crew 😬)

    Misconception 2: "The MAP sensor is only used as a backup when there is a TPS sensor failure"
    Again as above, this isn't the case. The MAP sensor certainly IS used as a back up for various purposes including approximating RF when TPS input is implausible. It's also used (when the engine isn't running) to capture a p_umg replacement value if the DME onboard pressure sensor is in error state.


    And this leads on to the most interesting of these misconceptions...

    Misconception 3: "The MAP sensor input is limited in the code to a max 2.5% adjustment factor"
    This one isn't wrong, so much as it's only part of the whole picture. It is true that in the function that calculates the RF adjustment as a result of pressure difference (it does this by taking the difference of final RF and RF calculated from pressure (p_umg - MAP_Pressure)) there are limits applied to the resultant rf adjustment to a max of 2.5 percentage points up and down. However the key thing that seems to have been missed is that the final RF value that it references to calculate the new RF pressure adjustment IS the pressure-adjusted value from the previous time the function ran. The function runs in the 10ms task, which means in the space of 100ms RF can be adjusted up down by up to 25 percentage points as a result of MAP sensor input. This isn't a limiting factor it's a smoothing factor.


    So what does this mean? In short, the MAP sensor is used to provide a pressure adjusted RF value which is used under part throttle conditions. The application of this pressure adjustment is smoothed to a maximum rate of change of 2.5% of max RF per 10ms.
    Nice work mate. I always thought it was strange for BMW to go to all that trouble to install a redundant component.

    It's great to have the correct answer after all these years.

    It also makes me feel a lot better after spending £800 on the MAP sensor and CSL rail, all those years ago 👍

    Leave a comment:


  • S54B32
    replied
    Originally posted by karter16 View Post
    I've been looking into the calculation of RF (relative fill) and how the MAP sensor etc. inputs into that, as it still seems to be an area of debate.

    From what I've seen so far the following misconceptions that float around can be addressed:

    Misconception 1: "The MAP sensor isn't used in normal use, the CSL runs pure AlphaN
    This is absolutely not the case, this may be due to a misinterpretation around how the status byte at 0x00ff807e is calculated, however in the happy path flow of the software the MAP sensor input is absolutely used (the difference between manifold pressure and ambient pressure is used to calculate an RF adjustment value). The amount of input it has appears to be limited to part throttle applications in low and mid-range RPM (hello drivability), but to say that the CSL runs pure AlphaN just isn't true (sorry AlphaN crew 😬)

    Misconception 2: "The MAP sensor is only used as a backup when there is a TPS sensor failure"
    Again as above, this isn't the case. The MAP sensor certainly IS used as a back up for various purposes including approximating RF when TPS input is implausible. It's also used (when the engine isn't running) to capture a p_umg replacement value if the DME onboard pressure sensor is in error state.


    And this leads on to the most interesting of these misconceptions...

    Misconception 3: "The MAP sensor input is limited in the code to a max 2.5% adjustment factor"
    This one isn't wrong, so much as it's only part of the whole picture. It is true that in the function that calculates the RF adjustment as a result of pressure difference (it does this by taking the difference of final RF and RF calculated from pressure (p_umg - MAP_Pressure)) there are limits applied to the resultant rf adjustment to a max of 2.5 percentage points up and down. However the key thing that seems to have been missed is that the final RF value that it references to calculate the new RF pressure adjustment IS the pressure-adjusted value from the previous time the function ran. The function runs in the 10ms task, which means in the space of 100ms RF can be adjusted up down by up to 25 percentage points as a result of MAP sensor input. This isn't a limiting factor it's a smoothing factor.


    So what does this mean? In short, the MAP sensor is used to provide a pressure adjusted RF value which is used under part throttle conditions. The application of this pressure adjustment is smoothed to a maximum rate of change of 2.5% of max RF per 10ms.
    I'm VERY happy that finally someone spends the time to bust this myth. Thank you for contributing this to the community!
    Just for all the skeptical persons out there, could you please share some screenshots of the relevant parts of the disassambly to make your findings about this bulletproof?

    Leave a comment:


  • heinzboehmer
    replied
    Originally posted by karter16 View Post
    However the key thing that seems to have been missed is that the final RF value that it references to calculate the new RF pressure adjustment IS the pressure-adjusted value from the previous time the function ran. The function runs in the 10ms task, which means in the space of 100ms RF can be adjusted up down by up to 25 percentage points as a result of MAP sensor input. This isn't a limiting factor it's a smoothing factor.
    This is some amazing insight. I hadn't seen this piece of info before. Thanks for sharing!

    Leave a comment:


  • karter16
    replied
    I've been looking into the calculation of RF (relative fill) and how the MAP sensor etc. inputs into that, as it still seems to be an area of debate.

    From what I've seen so far the following misconceptions that float around can be addressed:

    Misconception 1: "The MAP sensor isn't used in normal use, the CSL runs pure AlphaN"
    This is absolutely not the case, this may be due to a misinterpretation around how the status byte at 0x00ff807e is calculated, however in the happy path flow of the software the MAP sensor input is absolutely used (the difference between manifold pressure and ambient pressure is used to calculate an RF adjustment value). The amount of input it has appears to be limited to part throttle applications in low and mid-range RPM (hello drivability), but to say that the CSL runs pure AlphaN just isn't true (sorry AlphaN crew 😬)

    Misconception 2: "The MAP sensor is only used as a backup when there is a TPS sensor failure"
    Again as above, this isn't the case. The MAP sensor certainly IS used as a back up for various purposes including approximating RF when TPS input is implausible. It's also used (when the engine isn't running) to capture a p_umg replacement value if the DME onboard pressure sensor is in error state.


    And this leads on to the most interesting of these misconceptions...

    EDIT: I've adjusted two sentences in the below which were partially incorrect.

    Misconception 3: "The MAP sensor input is limited in the code to a max 2.5% adjustment factor"
    This one isn't wrong, so much as it's only part of the whole picture. It is true that in the function that calculates the RF adjustment as a result of pressure difference (it does this by taking the difference of final RF and RF calculated from pressure (p_umg - MAP_Pressure)) there are limits applied to the resultant rf adjustment to a max of 2.5 percentage points up and down. However the key thing that seems to have been missed is that the final RF value that it references to calculate the new RF pressure adjustment IS the pressure-adjusted (via ML) value from the previous time the function ran. This isn't a limiting factor it's a smoothing factor.


    So what does this mean? In short, the MAP sensor is used to provide a pressure adjusted RF value which is used under part throttle conditions. The application of this pressure adjustment is smoothed to a maximum rate of change.
    Last edited by karter16; 02-21-2025, 04:54 PM.

    Leave a comment:

Working...
X