Failures with GPIO and RTC after Zephyr project enabled TF-M with PROFILE_MEDIUM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Failures with GPIO and RTC after Zephyr project enabled TF-M with PROFILE_MEDIUM

1,294 Views
ClarkS
Contributor III

Attached is a zip of a simple VSCode / NXP MCUXpresso Zephyr project which demonstrates GPIO and RTC failures after enabling TF-M with PROFILE_MEDIUM at ISOLATION_LEVEL=2.

The project contains a simple overlay MCXN947 overlay file, a simple prj.conf file, and a couple simple c files. When the project reaches boot, zephyr has already configured TF-M. At boot the project attempts to toggle a couple GPIO. The code appears to work, no errors are thrown, but a logic analyzer shows the pins are not toggling. After that it prints some console messages with the time from the RTC. The time properly advances as it should however if the board is reset, the time is lost and starts at zero again. The RTC did not survive a reset.

If the TF-M configuration is removed and the project is changed to a simple zephyr non TF-M project, the GPIO and RTC will work as expected. The flash and debug process also work as expected. 

It is my hypothesis that the AHBSC controller is not configured properly and does not allow GPIO or the RTC to operate with non-secure code. 

Another problem of lesser severity is that I have been unable to configure launch.json to properly flash and then debug main.c or other non-secure code. 

I am using Zephyr 4.3.99...the latest zephyr version. VSCode and MCUXpresso are both up to date.

Tags (3)
0 Kudos
Reply
6 Replies

562 Views
ClarkS
Contributor III

I am still unable to get GPIO to work after configuring zephyr to implement TF-M. I have attempted to modify the blinky app  by adding TF-M and when I do, the LED no longer flashes.

Please provide a modification of the blinky sample app which simply enables TF-M. Ideally it should implement the best method of adjusting the AHBSC, SYSCON, and GPIO registers so as to enable GPIO. 

Is modifying target_cfg.c the only way to adjust these registers before main is executed? I hope there is a better method because I don’t like modifying my zephyr repo. 

0 Kudos
Reply

987 Views
ClarkS
Contributor III

I have been continuing to work on this with no success. I am preparing a reply to you with more information and a request for further help. I'll post it tomorrow. 

0 Kudos
Reply

1,251 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @ClarkS 

Can you share your code?

BR

Harry

Tags (3)
0 Kudos
Reply

1,236 Views
ClarkS
Contributor III

I had a zip of my project attached to the original post but it seems to have been deleted. I'll try again.

Nope zip is not supported. I'll try to attach the raw source files. You can take them and make your own project. Since there is a 5 file limit, I'll try to send them in two replies. 

THANK YOU for looking at this. This problem is a show stopper for me and I also think it might be a big problem for others also. 

0 Kudos
Reply

1,234 Views
ClarkS
Contributor III

Additional files below. If there is a way to send the project, let me know.

0 Kudos
Reply

1,210 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @ClarkS 

Thank you for your detailed description.

"

## Known Findings

1. **BusFault when reading AHBSC**: Non-secure code triggers immediate BusFault (BFAR: 0x400AC1D0) when attempting to read AHBSC controller registers
- This proves: At ISOLATION_LEVEL=2, NS is completely locked out from peripheral access verification
- AHBSC controller itself is in secure-protected memory space

2. **GPIO still doesn't work**: Even if AHBSC configuration is happening in secure world (which we can't v_erify), NS GPIO remains non-functional

"

According to the MCX Nx4x Reference Manual 73.1.2
Security considerations

 

Each GPIO module is also instantiated to use two module slots (for example, GPIO0 and GPIO0_alias).

At the Secure AHB controller, one slot can be configured for secure access while the other is configured for non-secure access.

The GPIO module implements Access protection that can be used to configure secure/non-secure and privileged/non-privileged access on a per pin basis

I think the following links are helpful to you.

NXP MCXN947 CPU1 cannot control GPIO · Issue #88521 · zephyrproject-rtos/zephyr

NXP MCXN947 CPU1 cannot control GPIO · Issue #88521 · zephyrproject-rtos/zephyr

MCXN947 failed to control GPIO in slave core (CPU1)

BR

Harry

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2321552%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EFailures%20with%20GPIO%20and%20RTC%20after%20Zephyr%20project%20enabled%20TF-M%20with%20PROFILE_MEDIUM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2321552%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EAttached%20is%20a%20zip%20of%20a%20simple%20VSCode%20%2F%20NXP%20MCUXpresso%20Zephyr%20project%20which%20demonstrates%20GPIO%20and%20RTC%20failures%20after%20enabling%20TF-M%20with%26nbsp%3BPROFILE_MEDIUM%20at%20ISOLATION_LEVEL%3D2.%3CBR%20%2F%3E%3CBR%20%2F%3EThe%20project%20contains%20a%20simple%20overlay%20MCXN947%20overlay%20file%2C%20a%20simple%20prj.conf%20file%2C%20and%20a%20couple%20simple%20c%20files.%20When%20the%20project%20reaches%20boot%2C%20zephyr%20has%20already%20configured%20TF-M.%20At%20boot%20the%20project%20attempts%20to%20toggle%20a%20couple%20GPIO.%20The%20code%20appears%20to%20work%2C%20no%20errors%20are%20thrown%2C%20but%20a%20logic%20analyzer%20shows%20the%20pins%20are%20not%20toggling.%20After%20that%20it%20prints%20some%20console%20messages%20with%20the%20time%20from%20the%20RTC.%20The%20time%20properly%20advances%20as%20it%20should%20however%20if%20the%20board%20is%20reset%2C%20the%20time%20is%20lost%20and%20starts%20at%20zero%20again.%20The%20RTC%20did%20not%20survive%20a%20reset.%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20the%20TF-M%20configuration%20is%20removed%20and%20the%20project%20is%20changed%20to%20a%20simple%20zephyr%20non%20TF-M%20project%2C%20the%20GPIO%20and%20RTC%20will%20work%20as%20expected.%20The%20flash%20and%20debug%20process%20also%20work%20as%20expected.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EIt%20is%20my%20hypothesis%20that%20the%20AHBSC%20controller%20is%20not%20configured%20properly%20and%20does%20not%20allow%20GPIO%20or%20the%20RTC%20to%20operate%20with%20non-secure%20code.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EAnother%20problem%20of%20lesser%20severity%20is%20that%20I%20have%20been%20unable%20to%20configure%20launch.json%20to%20properly%20flash%20and%20then%20debug%20main.c%20or%20other%20non-secure%20code.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EI%20am%20using%20Zephyr%204.3.99...the%20latest%20zephyr%20version.%20VSCode%20and%20MCUXpresso%20are%20both%20up%20to%20date.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2322612%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Failures%20with%20GPIO%20and%20RTC%20after%20Zephyr%20project%20enabled%20TF-M%20with%20PROFILE_MEDIUM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2322612%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EAdditional%20files%20below.%20If%20there%20is%20a%20way%20to%20send%20the%20project%2C%20let%20me%20know.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2322608%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Failures%20with%20GPIO%20and%20RTC%20after%20Zephyr%20project%20enabled%20TF-M%20with%20PROFILE_MEDIUM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2322608%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20had%20a%20zip%20of%20my%20project%20attached%20to%20the%20original%20post%20but%20it%20seems%20to%20have%20been%20deleted.%20I'll%20try%20again.%3CBR%20%2F%3E%3CBR%20%2F%3ENope%20zip%20is%20not%20supported.%20I'll%20try%20to%20attach%20the%20raw%20source%20files.%20You%20can%20take%20them%20and%20make%20your%20own%20project.%20Since%20there%20is%20a%205%20file%20limit%2C%20I'll%20try%20to%20send%20them%20in%20two%20replies.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3ETHANK%20YOU%20for%20looking%20at%20this.%20This%20problem%20is%20a%20show%20stopper%20for%20me%20and%20I%20also%20think%20it%20might%20be%20a%20big%20problem%20for%20others%20also.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2322403%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Failures%20with%20GPIO%20and%20RTC%20after%20Zephyr%20project%20enabled%20TF-M%20with%20PROFILE_MEDIUM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2322403%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F247187%22%20target%3D%22_blank%22%3E%40ClarkS%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECan%20you%20share%20your%20code%3F%3C%2FP%3E%0A%3CP%3EBR%3C%2FP%3E%0A%3CP%3EHarry%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2323057%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Failures%20with%20GPIO%20and%20RTC%20after%20Zephyr%20project%20enabled%20TF-M%20with%20PROFILE_MEDIUM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2323057%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F247187%22%20target%3D%22_blank%22%3E%40ClarkS%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThank%20you%20for%20your%20detailed%20description.%3C%2FP%3E%0A%3CP%3E%22%3C%2FP%3E%0A%3CP%3E%23%23%20Known%20Findings%3C%2FP%3E%0A%3CP%3E1.%20**BusFault%20when%20reading%20AHBSC**%3A%20Non-secure%20code%20triggers%20immediate%20BusFault%20(BFAR%3A%200x400AC1D0)%20when%20attempting%20to%20read%20AHBSC%20controller%20registers%3CBR%20%2F%3E-%20This%20proves%3A%20At%20ISOLATION_LEVEL%3D2%2C%20NS%20is%20completely%20locked%20out%20from%20peripheral%20access%20verification%3CBR%20%2F%3E-%20AHBSC%20controller%20itself%20is%20in%20secure-protected%20memory%20space%3C%2FP%3E%0A%3CP%3E2.%20**GPIO%20still%20doesn't%20work**%3A%20Even%20if%20AHBSC%20configuration%20is%20happening%20in%20secure%20world%20(which%20we%20can't%20v_erify)%2C%20NS%20GPIO%20remains%20non-functional%3C%2FP%3E%0A%3CP%3E%22%3C%2FP%3E%0A%3CP%3EAccording%20to%20the%26nbsp%3BMCX%20Nx4x%20Reference%20Manual%26nbsp%3B73.1.2%3CBR%20%2F%3ESecurity%20considerations%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorHarry_Zhang_2%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3EEach%20GPIO%20module%20is%20also%20instantiated%20to%20use%20two%20module%20slots%20(for%20example%2C%20GPIO0%20and%20GPIO0_alias).%3C%2FP%3E%0A%3CP%3EAt%20the%20Secure%20AHB%20controller%2C%20one%20slot%20can%20be%20configured%20for%20secure%20access%20while%20the%20other%20is%20configured%20for%20non-secure%20access.%3C%2FP%3E%0A%3CP%3EThe%20GPIO%20module%20implements%20Access%20protection%20that%20can%20be%20used%20to%20configure%20secure%2Fnon-secure%20and%20privileged%2Fnon-privileged%20access%20on%20a%20per%20pin%20basis%3C%2FP%3E%0A%3CP%3EI%20think%20the%20following%20links%20are%20helpful%20to%20you.%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fzephyrproject-rtos%2Fzephyr%2Fissues%2F88521%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3ENXP%20MCXN947%20CPU1%20cannot%20control%20GPIO%20%C2%B7%20Issue%20%2388521%20%C2%B7%20zephyrproject-rtos%2Fzephyr%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fzephyrproject-rtos%2Fzephyr%2Fpull%2F88523%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3ENXP%20MCXN947%20CPU1%20cannot%20control%20GPIO%20%C2%B7%20Issue%20%2388521%20%C2%B7%20zephyrproject-rtos%2Fzephyr%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FMCX-Microcontrollers%2FMCXN947-failed-to-control-GPIO-in-slave-core-CPU1%2Ftd-p%2F2250120%22%20target%3D%22_blank%22%3EMCXN947%20failed%20to%20control%20GPIO%20in%20slave%20core%20(CPU1)%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EBR%3C%2FP%3E%0A%3CP%3EHarry%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2329312%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Failures%20with%20GPIO%20and%20RTC%20after%20Zephyr%20project%20enabled%20TF-M%20with%20PROFILE_MEDIUM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2329312%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20have%20been%20continuing%20to%20work%20on%20this%20with%20no%20success.%20I%20am%20preparing%20a%20reply%20to%20you%20with%20more%20information%20and%20a%20request%20for%20further%20help.%20I'll%20post%20it%20tomorrow.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2341280%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Failures%20with%20GPIO%20and%20RTC%20after%20Zephyr%20project%20enabled%20TF-M%20with%20PROFILE_MEDIUM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2341280%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20am%20still%20unable%20to%20get%20GPIO%20to%20work%20after%20configuring%20zephyr%20to%20implement%20TF-M.%20I%20have%20attempted%20to%20modify%20the%20blinky%20app%20%26nbsp%3Bby%20adding%20TF-M%20and%20when%20I%20do%2C%20the%20LED%20no%20longer%20flashes.%3C%2FP%3E%3CP%3E%3CSPAN%3EPlease%20provide%20a%20modification%20of%20the%20blinky%20sample%20app%20which%20simply%20enables%20TF-M.%20Ideally%20it%20should%20implement%20the%20best%20method%20of%20adjusting%20the%20AHBSC%2C%20SYSCON%2C%20and%20GPIO%20registers%20so%20as%20to%20enable%20GPIO.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EIs%20modifying%20target_cfg.c%20the%20only%20way%20to%20adjust%20these%20registers%20before%20main%20is%20executed%3F%20I%20hope%20there%20is%20a%20better%20method%20because%20I%20don%E2%80%99t%20like%20modifying%20my%20zephyr%20repo.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E