50 | * PORT HAL provides the API for reading and writing register bit-fields belonging to the PORT module. 51 | *
52 | * @{ 53 | */ 54 | 55 | /******************************************************************************* 56 | * Definitions 57 | ******************************************************************************/ 58 | /******************************************************************************* 59 | * API 60 | ******************************************************************************/ 61 | 62 | #if defined(__cplusplus) 63 | extern "C" { 64 | #endif 65 | 66 | /*! 67 | * @name Configuration 68 | * @{ 69 | */ 70 | 71 | /*! 72 | * @brief Initializes the pins with the given configuration structure 73 | * 74 | * This function configures the pins with the options provided in the 75 | * given structure. 76 | * 77 | * @param[in] config the configuration structure 78 | */ 79 | void PINS_Init(const pin_settings_config_t * config); 80 | 81 | #if FEATURE_PINS_HAS_PULL_SELECTION 82 | /*! 83 | * @brief Configures the internal resistor. 84 | * 85 | * Pull configuration is valid in all digital pin muxing modes. 86 | * 87 | * @param[in] base port base pointer. 88 | * @param[in] pin port pin number 89 | * @param[in] pullConfig internal resistor pull feature selection 90 | * - PORT_PULL_NOT_ENABLED: internal pull-down or pull-up resistor is not enabled. 91 | * - PORT_PULL_DOWN_ENABLED: internal pull-down resistor is enabled. 92 | * - PORT_PULL_UP_ENABLED: internal pull-up resistor is enabled. 93 | */ 94 | static inline void PINS_SetPullSel(PORT_Type * const base, 95 | uint32_t pin, 96 | port_pull_config_t pullConfig) 97 | { 98 | DEV_ASSERT(pin < PORT_PCR_COUNT); 99 | switch (pullConfig) 100 | { 101 | case PORT_INTERNAL_PULL_NOT_ENABLED: 102 | { 103 | base->PCR[pin] &= ~(PORT_PCR_PE_MASK); 104 | } 105 | break; 106 | case PORT_INTERNAL_PULL_DOWN_ENABLED: 107 | { 108 | uint32_t regValue = base->PCR[pin]; 109 | regValue &= ~(PORT_PCR_PS_MASK); 110 | regValue |= PORT_PCR_PE(1U); 111 | base->PCR[pin] = regValue; 112 | } 113 | break; 114 | case PORT_INTERNAL_PULL_UP_ENABLED: 115 | { 116 | uint32_t regValue = base->PCR[pin]; 117 | regValue |= PORT_PCR_PE(1U); 118 | regValue |= PORT_PCR_PS(1U); 119 | base->PCR[pin] = regValue; 120 | } 121 | break; 122 | default: 123 | /* invalid command */ 124 | DEV_ASSERT(false); 125 | break; 126 | } 127 | } 128 | 129 | #endif /* if FEATURE_PINS_HAS_PULL_SELECTION */ 130 | 131 | /*! 132 | * @brief Configures the pin muxing. 133 | * 134 | * @param[in] base port base pointer 135 | * @param[in] pin port pin number 136 | * @param[in] mux pin muxing slot selection 137 | * - PORT_PIN_DISABLED: Pin disabled. 138 | * - PORT_MUX_AS_GPIO : Set as GPIO. 139 | * - PORT_MUX_ADC_INTERLEAVE : For ADC interleaved 140 | * - others : chip-specific. 141 | */ 142 | void PINS_SetMuxModeSel(PORT_Type * const base, 143 | uint32_t pin, 144 | port_mux_t mux); 145 | 146 | /*! 147 | * @brief Configures the port pin interrupt/DMA request. 148 | * 149 | * @param[in] base port base pointer. 150 | * @param[in] pin port pin number 151 | * @param[in] intConfig interrupt configuration 152 | * - PORT_INT_DISABLED : Interrupt/DMA request disabled. 153 | * - PORT_DMA_RISING_EDGE : DMA request on rising edge. 154 | * - PORT_DMA_FALLING_EDGE : DMA request on falling edge. 155 | * - PORT_DMA_EITHER_EDGE : DMA request on either edge. 156 | * - PORT_FLAG_RISING_EDGE : Flag sets on rising edge only. 157 | * - PORT_FLAG_FALLING_EDGE: Flag sets on falling edge only. 158 | * - PORT_FLAG_EITHER_EDGE : Flag sets on either edge only. 159 | * - PORT_INT_LOGIC_ZERO : Interrupt when logic zero. 160 | * - PORT_INT_RISING_EDGE : Interrupt on rising edge. 161 | * - PORT_INT_FALLING_EDGE : Interrupt on falling edge. 162 | * - PORT_INT_EITHER_EDGE : Interrupt on either edge. 163 | * - PORT_INT_LOGIC_ONE : Interrupt when logic one. 164 | * - PORT_HIGH_TRIGGER_OUT : Enable active high trigger output, flag is disabled. 165 | * - PORT_LOW_TRIGGER_OUT : Enable active low trigger output, flag is disabled. 166 | */ 167 | static inline void PINS_SetPinIntSel(PORT_Type * const base, 168 | uint32_t pin, 169 | port_interrupt_config_t intConfig) 170 | { 171 | DEV_ASSERT(pin < PORT_PCR_COUNT); 172 | uint32_t regValue = base->PCR[pin]; 173 | regValue &= ~(PORT_PCR_IRQC_MASK); 174 | regValue |= PORT_PCR_IRQC(intConfig); 175 | base->PCR[pin] = regValue; 176 | } 177 | 178 | /*! 179 | * @brief Gets the current port pin interrupt/DMA request configuration. 180 | * 181 | * @param[in] base port base pointer 182 | * @param[in] pin port pin number 183 | * @return interrupt configuration 184 | * - PORT_INT_DISABLED : Interrupt/DMA request disabled. 185 | * - PORT_DMA_RISING_EDGE : DMA request on rising edge. 186 | * - PORT_DMA_FALLING_EDGE : DMA request on falling edge. 187 | * - PORT_DMA_EITHER_EDGE : DMA request on either edge. 188 | * - PORT_FLAG_RISING_EDGE : Flag sets on rising edge only. 189 | * - PORT_FLAG_FALLING_EDGE: Flag sets on falling edge only. 190 | * - PORT_FLAG_EITHER_EDGE : Flag sets on either edge only. 191 | * - PORT_INT_LOGIC_ZERO : Interrupt when logic zero. 192 | * - PORT_INT_RISING_EDGE : Interrupt on rising edge. 193 | * - PORT_INT_FALLING_EDGE : Interrupt on falling edge. 194 | * - PORT_INT_EITHER_EDGE : Interrupt on either edge. 195 | * - PORT_INT_LOGIC_ONE : Interrupt when logic one. 196 | * - PORT_HIGH_TRIGGER_OUT : Enable active high trigger output, flag is disabled. 197 | * - PORT_LOW_TRIGGER_OUT : Enable active low trigger output, flag is disabled. 198 | */ 199 | static inline port_interrupt_config_t PINS_GetPinIntSel(const PORT_Type * const base, 200 | uint32_t pin) 201 | { 202 | DEV_ASSERT(pin < PORT_PCR_COUNT); 203 | uint32_t regValue = base->PCR[pin]; 204 | regValue = (regValue & PORT_PCR_IRQC_MASK) >> PORT_PCR_IRQC_SHIFT; 205 | 206 | return (port_interrupt_config_t)regValue; 207 | } 208 | 209 | /*! 210 | * @brief Clears the individual pin-interrupt status flag. 211 | * 212 | * @param[in] base port base pointer 213 | * @param[in] pin port pin number 214 | */ 215 | static inline void PINS_ClearPinIntFlagCmd(PORT_Type * const base, 216 | uint32_t pin) 217 | { 218 | DEV_ASSERT(pin < PORT_PCR_COUNT); 219 | uint32_t regValue = base->PCR[pin]; 220 | regValue &= ~(PORT_PCR_ISF_MASK); 221 | regValue |= PORT_PCR_ISF(1U); 222 | base->PCR[pin] = regValue; 223 | } 224 | 225 | /*! 226 | * @brief Enables digital filter for digital pin muxing 227 | * 228 | * @param[in] base port base pointer 229 | * @param[in] pin port pin number 230 | */ 231 | static inline void PINS_EnableDigitalFilter(PORT_Type * const base, 232 | uint32_t pin) 233 | { 234 | DEV_ASSERT(pin < PORT_PCR_COUNT); 235 | base->DFER |= (uint32_t)1U << pin; 236 | } 237 | 238 | /*! 239 | * @brief Disables digital filter for digital pin muxing 240 | * 241 | * @param[in] base port base pointer 242 | * @param[in] pin port pin number 243 | */ 244 | static inline void PINS_DisableDigitalFilter(PORT_Type * const base, 245 | uint32_t pin) 246 | { 247 | DEV_ASSERT(pin < PORT_PCR_COUNT); 248 | base->DFER &= ~((uint32_t)1U << pin); 249 | } 250 | 251 | /*! 252 | * @brief Configures digital filter clock for port with given configuration 253 | * 254 | * @param[in] base port base pointer 255 | * @param[in] config configuration struct 256 | */ 257 | static inline void PINS_ConfigDigitalFilter(PORT_Type * const base, 258 | const port_digital_filter_config_t * const config) 259 | { 260 | DEV_ASSERT(config->width <= PORT_DFWR_FILT_MASK); 261 | base->DFCR = PORT_DFCR_CS(config->clock); 262 | base->DFWR = PORT_DFWR_FILT(config->width); 263 | } 264 | 265 | /*! 266 | * @brief Reads the entire port interrupt status flag. 267 | * 268 | * @param[in] base port base pointer 269 | * @return all 32 pin interrupt status flags. For specific bit: 270 | * - 0: interrupt is not detected. 271 | * - 1: interrupt is detected. 272 | */ 273 | static inline uint32_t PINS_GetPortIntFlag(const PORT_Type * const base) 274 | { 275 | uint32_t regValue = base->ISFR; 276 | 277 | return regValue; 278 | } 279 | 280 | /*! 281 | * @brief Clears the entire port interrupt status flag. 282 | * 283 | * @param[in] base port base pointer 284 | */ 285 | static inline void PINS_ClearPortIntFlagCmd(PORT_Type * const base) 286 | { 287 | base->ISFR = PORT_ISFR_ISF_MASK; 288 | } 289 | 290 | /*! 291 | * @brief Quickly configures multiple pins with the same pin configuration. 292 | * 293 | * @param[in] base port base pointer 294 | * @param[in] pins pin mask where each bit represents one pin 295 | * @param[in] value the config value will be updated for the pins are set to '1' 296 | * @param[in] halfPort the lower or upper half of pin registers at the same port 297 | */ 298 | void PINS_SetGlobalPinControl(PORT_Type * const base, 299 | uint16_t pins, 300 | uint16_t value, 301 | port_global_control_pins_t halfPort); 302 | 303 | /*! 304 | * @brief Quickly configures multiple pins with the same interrupt configuration. 305 | * 306 | * @param[in] base port base pointer 307 | * @param[in] pins pin mask where each bit represents one pin 308 | * @param[in] value the config value will be updated for the pins are set to '1' 309 | * @param[in] halfPort the lower or upper half of pin registers at the same port 310 | */ 311 | void PINS_SetGlobalIntControl(PORT_Type * const base, 312 | uint16_t pins, 313 | uint16_t value, 314 | port_global_control_pins_t halfPort); 315 | 316 | 317 | #if FEATURE_PINS_HAS_OVER_CURRENT 318 | /*! 319 | * @brief Reads the entire over current port interrupt status flag. 320 | * 321 | * @param[in] base port base pointer 322 | * @return all 32 pin interrupt status flags. For specific bit: 323 | * - 0: interrupt is not detected. 324 | * - 1: interrupt is detected. 325 | */ 326 | static inline uint32_t PINS_GetOverCurPortIntFlag(const PORT_Type * const base) 327 | { 328 | return ((uint32_t)(base->OCFR)); 329 | } 330 | 331 | /*! 332 | * @brief Clears the entire over current port interrupt status flag. 333 | * 334 | * @param[in] base port base pointer 335 | */ 336 | static inline void PINS_ClearOverCurPortIntFlag(PORT_Type * const base) 337 | { 338 | base->ISFR = PORT_OCFR_OCF_MASK; 339 | } 340 | #endif /* FEATURE_PINS_HAS_OVER_CURRENT */ 341 | 342 | /*! @} */ 343 | 344 | /*! @} */ 345 | 346 | #if defined(__cplusplus) 347 | } 348 | #endif 349 | 350 | /*! @} */ 351 | 352 | #endif /* PINS_PORT_HW_ACCESS_H */ 353 | /******************************************************************************* 354 | * EOF 355 | ******************************************************************************/ 356 | -------------------------------------------------------------------------------- /Sources/NVM_Flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SummerFalls/UDS_S32K144_FlashDriver/cd5289c1df01f55d19ab565eebd82d6800d8b9bd/Sources/NVM_Flash.c -------------------------------------------------------------------------------- /Sources/NVM_Flash.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SummerFalls/UDS_S32K144_FlashDriver/cd5289c1df01f55d19ab565eebd82d6800d8b9bd/Sources/NVM_Flash.h -------------------------------------------------------------------------------- /Sources/main.c: -------------------------------------------------------------------------------- 1 | /* ################################################################### 2 | ** Filename : main.c 3 | ** Processor : S32K1xx 4 | ** Abstract : 5 | ** Main module. 6 | ** This module contains user's application code. 7 | ** Settings : 8 | ** Contents : 9 | ** No public methods 10 | ** 11 | ** ###################################################################*/ 12 | /*! 13 | ** @file main.c 14 | ** @version 01.00 15 | ** @brief 16 | ** Main module. 17 | ** This module contains user's application code. 18 | */ 19 | /*! 20 | ** @addtogroup main_module main module documentation 21 | ** @{ 22 | */ 23 | /* MODULE main */ 24 | 25 | /* Including necessary module. Cpu.h contains other modules needed for compiling.*/ 26 | #include "Cpu.h" 27 | #include "NVM_Flash.h" 28 | 29 | volatile int exit_code = 0; 30 | 31 | /* User includes (#include below this line is not maintained by Processor Expert) */ 32 | 33 | /*! 34 | \brief The main function for the project. 35 | \details The startup initialization sequence is the following: 36 | * - startup asm routine 37 | * - main() 38 | */ 39 | int main(void) 40 | { 41 | /* Write your local variable definition here */ 42 | /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ 43 | #ifdef PEX_RTOS_INIT 44 | PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */ 45 | #endif 46 | /*** End of Processor Expert internal initialization. ***/ 47 | /* Write your code here */ 48 | NVM_TestFlashDriver(); 49 | /* For example: for(;;) { } */ 50 | /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ 51 | /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/ 52 | #ifdef PEX_RTOS_START 53 | PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */ 54 | #endif 55 | /*** End of RTOS startup code. ***/ 56 | /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ 57 | for(;;) { 58 | if(exit_code != 0) { 59 | break; 60 | } 61 | } 62 | return exit_code; 63 | /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ 64 | } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/ 65 | 66 | /* END main */ 67 | /*! 68 | ** @} 69 | */ 70 | /* 71 | ** ################################################################### 72 | ** 73 | ** This file was created by Processor Expert 10.1 [05.21] 74 | ** for the NXP S32K series of microcontrollers. 75 | ** 76 | ** ################################################################### 77 | */ 78 | -------------------------------------------------------------------------------- /Sources/一键格式化所有代码(包括子目录)_精简版.bat: -------------------------------------------------------------------------------- 1 | for /R %%f in (*.c;*.h) do AStyle.exe -A1 -s4 -xV -S -w -Y -M60 -f -p -xg -H -xe -k3 -W3 -xb -j -xf -xh -c -xC200 -n -v %%f 2 | pause -------------------------------------------------------------------------------- /UDS_S32K144_FlashDriverExtracted.hex: -------------------------------------------------------------------------------- 1 | :020000041FFFDC 2 | :10800000110000004901000065020000B1030000FA 3 | :1080100080B588B000AFF860B9607A6000237B82D9 4 | :108020007B68BB61FB689B687B61BA687B699A422D 5 | :1080300010D3FB68DA687B691A44BB689A4209D995 6 | :10804000BA687B69D31A03F50003BB604FF4006381 7 | :10805000FB611BE0FB681B687B61BA687B699A4225 8 | :108060000ED3FB685A687B691A44BB689A4207D9E9 9 | :10807000BA687B69D31ABB604FF48053FB6105E09B 10 | :1080800001237B820023BB610023FB61FB695A1E35 11 | :10809000BB691340002B49D001237B8246E0294B6A 12 | :1080A0001B78DBB25BB2002B02DB02237B823DE05C 13 | :1080B000244B70221A70234B0922DA71214ABB68C3 14 | :1080C0001B0CDBB293711F4ABB681B0ADBB25371F6 15 | :1080D0001C4BBA68D2B21A7100237B82194A194B21 16 | :1080E0001B78DBB263F07F03DBB2137007E0FB6841 17 | :1080F0009B69B3F1FF3F02D0FB689B699847114B26 18 | :108100001B78DBB25BB2002BF1DA0E4B1B78DBB2D3 19 | :1081100003F07103002B01D001237B82BA69FB6954 20 | :10812000D31ABB61BA68FB691344BB60BB69002BFF 21 | :1081300002D07B8A002BB2D07B8A18462037BD46FE 22 | :1081400080BD00BF0000024080B586B000AFF8607F 23 | :10815000B96011461A460B46FB8013467B7100231B 24 | :108160007B82FB689B687B61BA687B699A420DD30E 25 | :10817000FB68DA687B691A44BB689A4206D9BA6818 26 | :108180007B69D31A03F50003BB6014E0FB681B682E 27 | :108190007B61BA687B699A420BD3FB685A687B693A 28 | :1081A0001A44BB689A4204D9BA687B69D31ABB6087 29 | :1081B00001E001237B827B8A002B4BD1284B1B786B 30 | :1081C000DBB25BB2002B02DB02237B8242E0244B5A 31 | :1081D00070221A70224B0122DA71214ABB681B0CF3 32 | :1081E000DBB293711E4ABB681B0ADBB253711C4B96 33 | :1081F000BA68D2B21A711A4AFB881B0A9BB2DBB268 34 | :10820000D372174BFA88D2B29A72154A7B7953729D 35 | :1082100000237B82124A124B1B78DBB263F07F0390 36 | :10822000DBB2137007E0FB689B69B3F1FF3F02D03C 37 | :10823000FB689B6998470A4B1B78DBB25BB2002B4B 38 | :10824000F1DA074B1B78DBB203F07103002B01D08E 39 | :1082500001237B827B8A18461837BD4680BD00BF4C 40 | :108260000000024080B588B000AFF860B9607A6065 41 | :108270003B600023FB827B6803F00703002B02D0E6 42 | :108280000123FB828BE0FB689B68BB61BA68BB691A 43 | :108290009A420DD3FB68DA68BB691A44BB689A42FC 44 | :1082A00006D9BA68BB69D31A03F50003BB6014E0B2 45 | :1082B000FB681B68BB61BA68BB699A420BD3FB6859 46 | :1082C0005A68BB691A44BB689A4204D9BA68BB6948 47 | :1082D000D31ABB6001E00123FB825AE0324B1B78CA 48 | :1082E000DBB25BB2002B02DB0223FB8251E02E4BA0 49 | :1082F00070221A702C4B0722DA712B4ABB681B0CB8 50 | :10830000DBB29371284ABB681B0ADBB25371264B60 51 | :10831000BA68D2B21A710023FB770CE0FA7F234BC4 52 | :108320001344BB61BB69FA7F39680A4412781A703A 53 | :10833000FB7F0133FB77FB7F072BEFD90023FB8209 54 | :10834000194A194B1B78DBB263F07F03DBB2137061 55 | :1083500007E0FB689B69B3F1FF3F02D0FB689B69B4 56 | :108360009847114B1B78DBB25BB2002BF1DA0E4B56 57 | :108370001B78DBB203F07103002B01D00123FB82D9 58 | :10838000BB680833BB607B68083B7B603B68083395 59 | :108390003B607B68002B02D0FB8A002B9ED0FB8ABF 60 | :1083A00018462037BD4680BD00000240080002404C 61 | :1083B00080B58AB000AFF860B9607A603B60002396 62 | :1083C000FB827B6803F00303002B02D00123FB82B6 63 | :1083D000A8E07B683B62FB689B687B62BA687B6A4B 64 | :1083E0009A420DD3FB68DA687B6A1A44BB689A42EA 65 | :1083F00006D9BA687B6AD31A03F50003BB6016E09E 66 | :10840000FB681B687B62BA687B6A9A420BD3FB6885 67 | :108410005A687B6A1A44BB689A4204D9BA687B6A74 68 | :10842000D31ABB6003E00123FB8200233B6273E0AD 69 | :108430003F4B1B78DBB25BB2002B02DB0223FB82DB 70 | :108440006AE03B4B70221A70394B0222DA71384ACB 71 | :10845000BB681B0CDBB29371354ABB681B0ADBB2ED 72 | :108460005371334BBA68D2B21A71314A97F834302B 73 | :10847000D3720023FB770CE0FA7F2E4B1344BB61D1 74 | :10848000BB69FA7F39680A4412781A70FB7F01339E 75 | :10849000FB77FB7F032BEFD90023FB82244A244B7D 76 | :1084A0001B78DBB263F07F03DBB2137007E0FB687D 77 | :1084B0009B69B3F1FF3F02D0FB689B6998471C4B57 78 | :1084C0001B78DBB25BB2002BF1DA194B1B78DBB205 79 | :1084D00003F07103002B01D00123FB82FB8A002BE8 80 | :1084E00011D0BB68B3F5000F07D3BA687B6A134499 81 | :1084F000A3F500023B6B1A600EE0BA687B6A1A446F 82 | :108500003B6B1A6008E03B6A043B3B623B68043308 83 | :108510003B60BB680433BB603B6A002B02D0FB8A24 84 | :10852000002B85D0FB8A18462837BD4680BD00BF8A 85 | :08853000000002400C000240B3 86 | :0400000300000411E4 87 | :00000001FF 88 | --------------------------------------------------------------------------------