Hi all,
I've been working with the S4A group for a while and am trying to be more active here. I have been doing some work on some bear metal support or proof of concept for the SAMD21. I have a very messy project that I was not really ready to share but I am having some issues. Talking to @carlos42421 over the weekend he thinks it might be a compiler or tooling issue. I am very much not an expert in the compiler stuff and hesitant to think it's something other than me doing strange or dumb stuff. ![]()
For reference I have this example project here: GitHub - pdshelley/SAMD21E at feature/hardfault · GitHub
This is supposed to be in the same style as the official Embedded Swift example projects here and has the same setup requirements: GitHub - swiftlang/swift-embedded-examples: A collection of example projects using Embedded Swift · GitHub
I'll try to briefly describe the issue here, happy to revise the example, add better steps, or slim it down if needed but I don't want to put hours of work into that if it's not needed.
In short I was working on a proof of concept for SPI, there is a setup function in SPI0.swift called "configure()". This function contains a huge Switch statement that I was using to debug and step through each line of code to figure out where things were breaking during early development. I got things working and was going to remove the Switch and when I simply move a single line from its own case then I get what I believe is a hard fault. There are comments on some of the lines and I can get the compiled files if that's easier to compare or check the LLVM output.
A lot of the lower level code has "@inline(__always)" as generally I believe these lower level register access calls should inline. Another way I was able to "fix" the hard fault issue was just removing the "@inline(__always)". I don't have this easily notated in the code but I can also get that example as well with very minimal effort.
I know all of this is still quite rough and needs refinement. I've been banging my head on the wall for the last few weeks and just don't know enough about how things work at this level and could use some direction or guidance. In the event that there is some strange edge case or bug I would love to help contribute whatever I can to fix it. Thanks.