ChibiOS  21.6.0
hal_serial_nor.c
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 /**
18  * @file hal_serial_nor.c
19  * @brief Serial NOR serial flash driver code.
20  *
21  * @addtogroup HAL_SERIAL_NOR
22  * @{
23  */
24 
25 #include "hal.h"
26 #include "hal_serial_nor.h"
27 
28 /*===========================================================================*/
29 /* Driver local definitions. */
30 /*===========================================================================*/
31 
32 /*===========================================================================*/
33 /* Driver exported variables. */
34 /*===========================================================================*/
35 
36 /*===========================================================================*/
37 /* Driver local variables and types. */
38 /*===========================================================================*/
39 
40 static const flash_descriptor_t *snor_get_descriptor(void *instance);
41 static flash_error_t snor_read(void *instance, flash_offset_t offset,
42  size_t n, uint8_t *rp);
43 static flash_error_t snor_program(void *instance, flash_offset_t offset,
44  size_t n, const uint8_t *pp);
45 static flash_error_t snor_start_erase_all(void *instance);
46 static flash_error_t snor_start_erase_sector(void *instance,
47  flash_sector_t sector);
48 static flash_error_t snor_verify_erase(void *instance,
49  flash_sector_t sector);
50 static flash_error_t snor_query_erase(void *instance, uint32_t *msec);
51 static flash_error_t snor_read_sfdp(void *instance, flash_offset_t offset,
52  size_t n, uint8_t *rp);
53 
54 /**
55  * @brief Virtual methods table.
56  */
57 static const struct SNORDriverVMT snor_vmt = {
58  (size_t)0,
59  snor_get_descriptor, snor_read, snor_program,
60  snor_start_erase_all, snor_start_erase_sector,
61  snor_query_erase, snor_verify_erase,
62  snor_read_sfdp
63 };
64 
65 /*===========================================================================*/
66 /* Driver local functions. */
67 /*===========================================================================*/
68 
69 /**
70  * @brief Returns a pointer to the device descriptor.
71  *
72  * @param[in] instance instance pointer
73  * @return Pointer to a static descriptor structure.
74  */
75 static const flash_descriptor_t *snor_get_descriptor(void *instance) {
76  SNORDriver *devp = (SNORDriver *)instance;
77 
78  osalDbgCheck(instance != NULL);
79  osalDbgAssert((devp->state != FLASH_UNINIT) && (devp->state != FLASH_STOP),
80  "invalid state");
81 
82  return &snor_descriptor;
83 }
84 
85 static flash_error_t snor_read(void *instance, flash_offset_t offset,
86  size_t n, uint8_t *rp) {
87  SNORDriver *devp = (SNORDriver *)instance;
88  flash_error_t err;
89 
90  osalDbgCheck((instance != NULL) && (rp != NULL) && (n > 0U));
91  osalDbgCheck((size_t)offset + n <= (size_t)snor_descriptor.sectors_count *
92  (size_t)snor_descriptor.sectors_size);
93  osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
94  "invalid state");
95 
96  if (devp->state == FLASH_ERASE) {
97  return FLASH_BUSY_ERASING;
98  }
99 
100  /* Bus acquired.*/
101  bus_acquire(devp->config->busp, devp->config->buscfg);
102 
103  /* FLASH_READY state while the operation is performed.*/
104  devp->state = FLASH_READ;
105 
106  /* Actual read implementation.*/
107  err = snor_device_read(devp, offset, n, rp);
108 
109  /* Ready state again.*/
110  devp->state = FLASH_READY;
111 
112  /* Bus released.*/
113  bus_release(devp->config->busp);
114 
115  return err;
116 }
117 
118 static flash_error_t snor_program(void *instance, flash_offset_t offset,
119  size_t n, const uint8_t *pp) {
120  SNORDriver *devp = (SNORDriver *)instance;
121  flash_error_t err;
122 
123  osalDbgCheck((instance != NULL) && (pp != NULL) && (n > 0U));
124  osalDbgCheck((size_t)offset + n <= (size_t)snor_descriptor.sectors_count *
125  (size_t)snor_descriptor.sectors_size);
126  osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
127  "invalid state");
128 
129  if (devp->state == FLASH_ERASE) {
130  return FLASH_BUSY_ERASING;
131  }
132 
133  /* Bus acquired.*/
134  bus_acquire(devp->config->busp, devp->config->buscfg);
135 
136  /* FLASH_PGM state while the operation is performed.*/
137  devp->state = FLASH_PGM;
138 
139  /* Actual program implementation.*/
140  err = snor_device_program(devp, offset, n, pp);
141 
142  /* Ready state again.*/
143  devp->state = FLASH_READY;
144 
145  /* Bus released.*/
146  bus_release(devp->config->busp);
147 
148  return err;
149 }
150 
151 static flash_error_t snor_start_erase_all(void *instance) {
152  SNORDriver *devp = (SNORDriver *)instance;
153  flash_error_t err;
154 
155  osalDbgCheck(instance != NULL);
156  osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
157  "invalid state");
158 
159  if (devp->state == FLASH_ERASE) {
160  return FLASH_BUSY_ERASING;
161  }
162 
163  /* Bus acquired.*/
164  bus_acquire(devp->config->busp, devp->config->buscfg);
165 
166  /* FLASH_ERASE state while the operation is performed.*/
167  devp->state = FLASH_ERASE;
168 
169  /* Actual erase implementation.*/
170  err = snor_device_start_erase_all(devp);
171 
172  /* Ready state again.*/
173  devp->state = FLASH_READY;
174 
175  /* Bus released.*/
176  bus_release(devp->config->busp);
177 
178  return err;
179 }
180 
181 static flash_error_t snor_start_erase_sector(void *instance,
182  flash_sector_t sector) {
183  SNORDriver *devp = (SNORDriver *)instance;
184  flash_error_t err;
185 
186  osalDbgCheck(instance != NULL);
187  osalDbgCheck(sector < snor_descriptor.sectors_count);
188  osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
189  "invalid state");
190 
191  if (devp->state == FLASH_ERASE) {
192  return FLASH_BUSY_ERASING;
193  }
194 
195  /* Bus acquired.*/
196  bus_acquire(devp->config->busp, devp->config->buscfg);
197 
198  /* FLASH_ERASE state while the operation is performed.*/
199  devp->state = FLASH_ERASE;
200 
201  /* Actual erase implementation.*/
202  err = snor_device_start_erase_sector(devp, sector);
203 
204  /* Bus released.*/
205  bus_release(devp->config->busp);
206 
207  return err;
208 }
209 
210 static flash_error_t snor_verify_erase(void *instance,
211  flash_sector_t sector) {
212  SNORDriver *devp = (SNORDriver *)instance;
213  flash_error_t err;
214 
215  osalDbgCheck(instance != NULL);
216  osalDbgCheck(sector < snor_descriptor.sectors_count);
217  osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
218  "invalid state");
219 
220  if (devp->state == FLASH_ERASE) {
221  return FLASH_BUSY_ERASING;
222  }
223 
224  /* Bus acquired.*/
225  bus_acquire(devp->config->busp, devp->config->buscfg);
226 
227  /* FLASH_READY state while the operation is performed.*/
228  devp->state = FLASH_READ;
229 
230  /* Actual verify erase implementation.*/
231  err = snor_device_verify_erase(devp, sector);
232 
233  /* Ready state again.*/
234  devp->state = FLASH_READY;
235 
236  /* Bus released.*/
237  bus_release(devp->config->busp);
238 
239  return err;
240 }
241 
242 static flash_error_t snor_query_erase(void *instance, uint32_t *msec) {
243  SNORDriver *devp = (SNORDriver *)instance;
244  flash_error_t err;
245 
246  osalDbgCheck(instance != NULL);
247  osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
248  "invalid state");
249 
250  /* If there is an erase in progress then the device must be checked.*/
251  if (devp->state == FLASH_ERASE) {
252 
253  /* Bus acquired.*/
254  bus_acquire(devp->config->busp, devp->config->buscfg);
255 
256  /* Actual query erase implementation.*/
257  err = snor_device_query_erase(devp, msec);
258 
259  /* The device is ready to accept commands.*/
260  if (err == FLASH_NO_ERROR) {
261  devp->state = FLASH_READY;
262  }
263 
264  /* Bus released.*/
265  bus_release(devp->config->busp);
266  }
267  else {
268  err = FLASH_NO_ERROR;
269  }
270 
271  return err;
272 }
273 
274 static flash_error_t snor_read_sfdp(void *instance, flash_offset_t offset,
275  size_t n, uint8_t *rp) {
276  SNORDriver *devp = (SNORDriver *)instance;
277  flash_error_t err;
278 
279  osalDbgCheck((instance != NULL) && (rp != NULL) && (n > 0U));
280  osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
281  "invalid state");
282 
283  if (devp->state == FLASH_ERASE) {
284  return FLASH_BUSY_ERASING;
285  }
286 
287  /* Bus acquired.*/
288  bus_acquire(devp->config->busp, devp->config->buscfg);
289 
290  /* Actual read SFDP implementation.*/
291  err = snor_device_read_sfdp(devp, offset, n, rp);
292 
293  /* The device is ready to accept commands.*/
294  if (err == FLASH_NO_ERROR) {
295  devp->state = FLASH_READY;
296  }
297 
298  /* Bus released.*/
299  bus_release(devp->config->busp);
300 
301  return err;
302 }
303 
304 /*===========================================================================*/
305 /* Driver exported functions. */
306 /*===========================================================================*/
307 
308 #if ((SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) && \
309  (SNOR_SHARED_BUS == TRUE)) || defined(__DOXYGEN__)
310 /**
311  * @brief Bus acquisition and lock.
312  *
313  * @param[in] busp pointer to the bus driver
314  * @param[in] config bus configuration
315  *
316  * @notapi
317  */
318 void bus_acquire(BUSDriver *busp, const BUSConfig *config) {
319 
320  (void)config;
321 
322  wspiAcquireBus(busp);
323  if (busp->config != config) {
324  wspiStart(busp, config);
325  }
326 }
327 
328 /**
329  * @brief Bus release.
330  *
331  * @param[in] busp pointer to the bus driver
332  *
333  * @notapi
334  */
335 void bus_release(BUSDriver *busp) {
336 
337  wspiReleaseBus(busp);
338 }
339 #endif
340 
341 #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_SPI) && \
342  (SNOR_SHARED_BUS == TRUE)
343 void bus_acquire(BUSDriver *busp, const BUSConfig *config) {
344 
345  spiAcquireBus(busp);
346  if (busp->config != config) {
347  spiStart(busp, config);
348  }
349 }
350 
351 void bus_release(BUSDriver *busp) {
352 
353  spiReleaseBus(busp);
354 }
355 #endif
356 
357 /**
358  * @brief Stops the underlying bus driver.
359  *
360  * @param[in] busp pointer to the bus driver
361  *
362  * @notapi
363  */
364 void bus_stop(BUSDriver *busp) {
365 
366 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
367  wspiStop(busp);
368 #else
369  spiStop(busp);
370 #endif
371 }
372 
373 /**
374  * @brief Sends a naked command.
375  *
376  * @param[in] busp pointer to the bus driver
377  * @param[in] cmd instruction code
378  *
379  * @notapi
380  */
381 void bus_cmd(BUSDriver *busp, uint32_t cmd) {
382 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
383  wspi_command_t mode;
384 
385  mode.cmd = cmd;
386  mode.cfg = SNOR_WSPI_CFG_CMD;
387  mode.addr = 0U;
388  mode.alt = 0U;
389  mode.dummy = 0U;
390  wspiCommand(busp, &mode);
391 #else
392  uint8_t buf[1];
393 
394  spiSelect(busp);
395  buf[0] = cmd;
396  spiSend(busp, 1, buf);
397  spiUnselect(busp);
398 #endif
399 }
400 
401 /**
402  * @brief Sends a command followed by a data transmit phase.
403  *
404  * @param[in] busp pointer to the bus driver
405  * @param[in] cmd instruction code
406  * @param[in] n number of bytes to receive
407  * @param[in] p data buffer
408  *
409  * @notapi
410  */
411 void bus_cmd_send(BUSDriver *busp, uint32_t cmd, size_t n, const uint8_t *p) {
412 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
413  wspi_command_t mode;
414 
415  mode.cmd = cmd;
416  mode.cfg = SNOR_WSPI_CFG_CMD_DATA;
417  mode.addr = 0U;
418  mode.alt = 0U;
419  mode.dummy = 0U;
420  wspiSend(busp, &mode, n, p);
421 #else
422  uint8_t buf[1];
423 
424  spiSelect(busp);
425  buf[0] = cmd;
426  spiSend(busp, 1, buf);
427  spiSend(busp, n, p);
428  spiUnselect(busp);
429 #endif
430 }
431 
432 /**
433  * @brief Sends a command followed by a data receive phase.
434  *
435  * @param[in] busp pointer to the bus driver
436  * @param[in] cmd instruction code
437  * @param[in] n number of bytes to receive
438  * @param[out] p data buffer
439  *
440  * @notapi
441  */
442 void bus_cmd_receive(BUSDriver *busp,
443  uint32_t cmd,
444  size_t n,
445  uint8_t *p) {
446 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
447  wspi_command_t mode;
448 
449  mode.cmd = cmd;
450  mode.cfg = SNOR_WSPI_CFG_CMD_DATA;
451  mode.addr = 0U;
452  mode.alt = 0U;
453  mode.dummy = 0U;
454  wspiReceive(busp, &mode, n, p);
455 #else
456  uint8_t buf[1];
457 
458  spiSelect(busp);
459  buf[0] = cmd;
460  spiSend(busp, 1, buf);
461  spiReceive(busp, n, p);
462  spiUnselect(busp);
463 #endif
464 }
465 
466 /**
467  * @brief Sends a command followed by a flash address.
468  *
469  * @param[in] busp pointer to the bus driver
470  * @param[in] cmd instruction code
471  * @param[in] offset flash offset
472  *
473  * @notapi
474  */
475 void bus_cmd_addr(BUSDriver *busp, uint32_t cmd, flash_offset_t offset) {
476 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
477  wspi_command_t mode;
478 
479  mode.cmd = cmd;
480  mode.cfg = SNOR_WSPI_CFG_CMD_ADDR;
481  mode.addr = offset;
482  mode.alt = 0U;
483  mode.dummy = 0U;
484  wspiCommand(busp, &mode);
485 #else
486  uint8_t buf[4];
487 
488  spiSelect(busp);
489  buf[0] = cmd;
490  buf[1] = (uint8_t)(offset >> 16);
491  buf[2] = (uint8_t)(offset >> 8);
492  buf[3] = (uint8_t)(offset >> 0);
493  spiSend(busp, 4, buf);
494  spiUnselect(busp);
495 #endif
496 }
497 
498 /**
499  * @brief Sends a command followed by a flash address and a data transmit
500  * phase.
501  *
502  * @param[in] busp pointer to the bus driver
503  * @param[in] cmd instruction code
504  * @param[in] offset flash offset
505  * @param[in] n number of bytes to receive
506  * @param[in] p data buffer
507  *
508  * @notapi
509  */
510 void bus_cmd_addr_send(BUSDriver *busp,
511  uint32_t cmd,
512  flash_offset_t offset,
513  size_t n,
514  const uint8_t *p) {
515 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
516  wspi_command_t mode;
517 
518  mode.cmd = cmd;
519  mode.cfg = SNOR_WSPI_CFG_CMD_ADDR_DATA;
520  mode.addr = offset;
521  mode.alt = 0U;
522  mode.dummy = 0U;
523  wspiSend(busp, &mode, n, p);
524 #else
525  uint8_t buf[4];
526 
527  spiSelect(busp);
528  buf[0] = cmd;
529  buf[1] = (uint8_t)(offset >> 16);
530  buf[2] = (uint8_t)(offset >> 8);
531  buf[3] = (uint8_t)(offset >> 0);
532  spiSend(busp, 4, buf);
533  spiSend(busp, n, p);
534  spiUnselect(busp);
535 #endif
536 }
537 
538 /**
539  * @brief Sends a command followed by a flash address and a data receive
540  * phase.
541  *
542  * @param[in] busp pointer to the bus driver
543  * @param[in] cmd instruction code
544  * @param[in] offset flash offset
545  * @param[in] n number of bytes to receive
546  * @param[out] p data buffer
547  *
548  * @notapi
549  */
550 void bus_cmd_addr_receive(BUSDriver *busp,
551  uint32_t cmd,
552  flash_offset_t offset,
553  size_t n,
554  uint8_t *p) {
555 #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI
556  wspi_command_t mode;
557 
558  mode.cmd = cmd;
559  mode.cfg = SNOR_WSPI_CFG_CMD_ADDR_DATA;
560  mode.addr = offset;
561  mode.alt = 0U;
562  mode.dummy = 0U;
563  wspiReceive(busp, &mode, n, p);
564 #else
565  uint8_t buf[4];
566 
567  spiSelect(busp);
568  buf[0] = cmd;
569  buf[1] = (uint8_t)(offset >> 16);
570  buf[2] = (uint8_t)(offset >> 8);
571  buf[3] = (uint8_t)(offset >> 0);
572  spiSend(busp, 4, buf);
573  spiReceive(busp, n, p);
574  spiUnselect(busp);
575 #endif
576 }
577 
578 #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) || defined(__DOXYGEN__)
579 /**
580  * @brief Sends a command followed by dummy cycles and a
581  * data receive phase.
582  *
583  * @param[in] busp pointer to the bus driver
584  * @param[in] cmd instruction code
585  * @param[in] dummy number of dummy cycles
586  * @param[in] n number of bytes to receive
587  * @param[out] p data buffer
588  *
589  * @notapi
590  */
591 void bus_cmd_dummy_receive(BUSDriver *busp,
592  uint32_t cmd,
593  uint32_t dummy,
594  size_t n,
595  uint8_t *p) {
596  wspi_command_t mode;
597 
598  mode.cmd = cmd;
599  mode.cfg = SNOR_WSPI_CFG_CMD_DATA;
600  mode.addr = 0U;
601  mode.alt = 0U;
602  mode.dummy = dummy;
603  wspiReceive(busp, &mode, n, p);
604 }
605 
606 /**
607  * @brief Sends a command followed by a flash address, dummy cycles and a
608  * data receive phase.
609  *
610  * @param[in] busp pointer to the bus driver
611  * @param[in] cmd instruction code
612  * @param[in] offset flash offset
613  * @param[in] dummy number of dummy cycles
614  * @param[in] n number of bytes to receive
615  * @param[out] p data buffer
616  *
617  * @notapi
618  */
619 void bus_cmd_addr_dummy_receive(BUSDriver *busp,
620  uint32_t cmd,
621  flash_offset_t offset,
622  uint32_t dummy,
623  size_t n,
624  uint8_t *p) {
625  wspi_command_t mode;
626 
627  mode.cmd = cmd;
628  mode.cfg = SNOR_WSPI_CFG_CMD_ADDR_DATA;
629  mode.addr = offset;
630  mode.alt = 0U;
631  mode.dummy = dummy;
632  wspiReceive(busp, &mode, n, p);
633 }
634 #endif /* SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI */
635 
636 /**
637  * @brief Initializes an instance.
638  *
639  * @param[out] devp pointer to the @p SNORDriver object
640  *
641  * @init
642  */
644 
645  osalDbgCheck(devp != NULL);
646 
647  devp->vmt = &snor_vmt;
648  devp->state = FLASH_STOP;
649  devp->config = NULL;
650 }
651 
652 /**
653  * @brief Configures and activates SNOR driver.
654  *
655  * @param[in] devp pointer to the @p SNORDriver object
656  * @param[in] config pointer to the configuration
657  *
658  * @api
659  */
660 void snorStart(SNORDriver *devp, const SNORConfig *config) {
661 
662  osalDbgCheck((devp != NULL) && (config != NULL));
663  osalDbgAssert(devp->state != FLASH_UNINIT, "invalid state");
664 
665  devp->config = config;
666 
667  if (devp->state == FLASH_STOP) {
668 
669  /* Bus acquisition.*/
670  bus_acquire(devp->config->busp, devp->config->buscfg);
671 
672  /* Device identification and initialization.*/
673  snor_device_init(devp);
674 
675  /* Driver in ready state.*/
676  devp->state = FLASH_READY;
677 
678  /* Bus release.*/
679  bus_release(devp->config->busp);
680  }
681 }
682 
683 /**
684  * @brief Deactivates the SNOR driver.
685  *
686  * @param[in] devp pointer to the @p SNORDriver object
687  *
688  * @api
689  */
690 void snorStop(SNORDriver *devp) {
691 
692  osalDbgCheck(devp != NULL);
693  osalDbgAssert(devp->state != FLASH_UNINIT, "invalid state");
694 
695  if (devp->state != FLASH_STOP) {
696 
697  /* Bus acquisition.*/
698  bus_acquire(devp->config->busp, devp->config->buscfg);
699 
700  /* Stopping bus device.*/
701  bus_stop(devp->config->busp);
702 
703  /* Driver stopped.*/
704  devp->state = FLASH_STOP;
705 
706  /* Bus release.*/
707  bus_release(devp->config->busp);
708 
709  /* Deleting current configuration.*/
710  devp->config = NULL;
711  }
712 }
713 
714 #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) || defined(__DOXYGEN__)
715 #if (WSPI_SUPPORTS_MEMMAP == TRUE) || defined(__DOXYGEN__)
716 /**
717  * @brief Enters the memory Mapping mode.
718  * @details The memory mapping mode is only available when the WSPI mode
719  * is selected and the underlying WSPI controller supports the
720  * feature.
721  *
722  * @param[in] devp pointer to the @p SNORDriver object
723  * @param[out] addrp pointer to the memory start address of the mapped
724  * flash or @p NULL
725  *
726  * @api
727  */
728 void snorMemoryMap(SNORDriver *devp, uint8_t **addrp) {
729 
730  /* Bus acquisition.*/
731  bus_acquire(devp->config->busp, devp->config->buscfg);
732 
733 #if SNOR_DEVICE_SUPPORTS_XIP == TRUE
734  /* Activating XIP mode in the device.*/
735  snor_activate_xip(devp);
736 #endif
737 
738  /* Starting WSPI memory mapped mode.*/
739  wspiMapFlash(devp->config->busp, &snor_memmap_read, addrp);
740 
741  /* Bus release.*/
742  bus_release(devp->config->busp);
743 }
744 
745 /**
746  * @brief Leaves the memory Mapping mode.
747  *
748  * @param[in] devp pointer to the @p SNORDriver object
749  *
750  * @api
751  */
753 
754  /* Bus acquisition.*/
755  bus_acquire(devp->config->busp, devp->config->buscfg);
756 
757  /* Stopping WSPI memory mapped mode.*/
758  wspiUnmapFlash(devp->config->busp);
759 
760 #if SNOR_DEVICE_SUPPORTS_XIP == TRUE
761  snor_reset_xip(devp);
762 #endif
763 
764  /* Bus release.*/
765  bus_release(devp->config->busp);
766 }
767 #endif /* WSPI_SUPPORTS_MEMMAP == TRUE */
768 #endif /* SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI */
769 
770 /** @} */
bus_cmd_dummy_receive
void bus_cmd_dummy_receive(BUSDriver *busp, uint32_t cmd, uint32_t dummy, size_t n, uint8_t *p)
Sends a command followed by dummy cycles and a data receive phase.
Definition: hal_serial_nor.c:591
bus_release
void bus_release(BUSDriver *busp)
Bus release.
Definition: hal_serial_nor.c:335
spiSelect
void spiSelect(SPIDriver *spip)
Asserts the slave select signal and prepares for transfers.
Definition: hal_spi.c:134
SNORDriver
Type of SNOR flash class.
Definition: hal_serial_nor.h:127
wspi_command_t
Type of a WSPI command descriptor.
Definition: hal_wspi.h:101
wspi_command_t::addr
uint32_t addr
Address phase data.
Definition: hal_wspi.h:113
hal.h
HAL subsystem header.
wspiAcquireBus
void wspiAcquireBus(WSPIDriver *wspip)
Gains exclusive access to the WSPI bus.
Definition: hal_wspi.c:384
spiReceive
void spiReceive(SPIDriver *spip, size_t n, void *rxbuf)
Receives data from the SPI bus.
Definition: hal_spi.c:416
wspiStart
void wspiStart(WSPIDriver *wspip, const WSPIConfig *config)
Configures and activates the WSPI peripheral.
Definition: hal_wspi.c:91
snorMemoryMap
void snorMemoryMap(SNORDriver *devp, uint8_t **addrp)
Enters the memory Mapping mode.
Definition: hal_serial_nor.c:728
SNORConfig
Type of a SNOR configuration structure.
Definition: hal_serial_nor.h:91
wspiUnmapFlash
void wspiUnmapFlash(WSPIDriver *wspip)
Unmaps from memory space a WSPI flash device.
Definition: hal_wspi.c:357
bus_cmd_addr_receive
void bus_cmd_addr_receive(BUSDriver *busp, uint32_t cmd, flash_offset_t offset, size_t n, uint8_t *p)
Sends a command followed by a flash address and a data receive phase.
Definition: hal_serial_nor.c:550
bus_acquire
void bus_acquire(BUSDriver *busp, const BUSConfig *config)
Bus acquisition and lock.
Definition: hal_serial_nor.c:318
wspi_command_t::dummy
uint32_t dummy
Number of dummy cycles to be inserted.
Definition: hal_wspi.h:121
flash_descriptor_t
Type of a flash device descriptor.
Definition: hal_flash.h:137
wspiStop
void wspiStop(WSPIDriver *wspip)
Deactivates the WSPI peripheral.
Definition: hal_wspi.c:116
wspiReleaseBus
void wspiReleaseBus(WSPIDriver *wspip)
Releases exclusive access to the WSPI bus.
Definition: hal_wspi.c:400
SNORDriverVMT
SNOR virtual methods table.
Definition: hal_serial_nor.h:118
snor_vmt
static const struct SNORDriverVMT snor_vmt
Virtual methods table.
Definition: hal_serial_nor.c:57
SNORDriver::vmt
const struct SNORDriverVMT * vmt
SNORDriver Virtual Methods Table.
Definition: hal_serial_nor.h:131
snor_get_descriptor
static const flash_descriptor_t * snor_get_descriptor(void *instance)
Returns a pointer to the device descriptor.
Definition: hal_serial_nor.c:75
flash_sector_t
uint32_t flash_sector_t
Type of a flash sector number.
Definition: hal_flash.h:118
bus_cmd_receive
void bus_cmd_receive(BUSDriver *busp, uint32_t cmd, size_t n, uint8_t *p)
Sends a command followed by a data receive phase.
Definition: hal_serial_nor.c:442
spiStop
void spiStop(SPIDriver *spip)
Deactivates the SPI peripheral.
Definition: hal_spi.c:111
snorObjectInit
void snorObjectInit(SNORDriver *devp)
Initializes an instance.
Definition: hal_serial_nor.c:643
hal_serial_nor.h
Serial NOR driver header.
spiReleaseBus
void spiReleaseBus(SPIDriver *spip)
Releases exclusive access to the SPI bus.
Definition: hal_spi.c:459
bus_cmd_addr_dummy_receive
void bus_cmd_addr_dummy_receive(BUSDriver *busp, uint32_t cmd, flash_offset_t offset, uint32_t dummy, size_t n, uint8_t *p)
Sends a command followed by a flash address, dummy cycles and a data receive phase.
Definition: hal_serial_nor.c:619
spiSend
void spiSend(SPIDriver *spip, size_t n, const void *txbuf)
Sends data over the SPI bus.
Definition: hal_spi.c:386
bus_cmd_send
void bus_cmd_send(BUSDriver *busp, uint32_t cmd, size_t n, const uint8_t *p)
Sends a command followed by a data transmit phase.
Definition: hal_serial_nor.c:411
spiAcquireBus
void spiAcquireBus(SPIDriver *spip)
Gains exclusive access to the SPI bus.
Definition: hal_spi.c:443
spiStart
void spiStart(SPIDriver *spip, const SPIConfig *config)
Configures and activates the SPI peripheral.
Definition: hal_spi.c:91
osalDbgCheck
#define osalDbgCheck(c)
Function parameters check.
Definition: osal.h:284
wspiReceive
bool wspiReceive(WSPIDriver *wspip, const wspi_command_t *cmdp, size_t n, uint8_t *rxbuf)
Sends a command then receives data over the WSPI bus.
Definition: hal_wspi.c:296
wspiSend
bool wspiSend(WSPIDriver *wspip, const wspi_command_t *cmdp, size_t n, const uint8_t *txbuf)
Sends a command with data over the WSPI bus.
Definition: hal_wspi.c:258
bus_stop
void bus_stop(BUSDriver *busp)
Stops the underlying bus driver.
Definition: hal_serial_nor.c:364
flash_error_t
flash_error_t
Type of a flash error code.
Definition: hal_flash.h:99
wspi_command_t::alt
uint32_t alt
Alternate phase data.
Definition: hal_wspi.h:117
wspiCommand
bool wspiCommand(WSPIDriver *wspip, const wspi_command_t *cmdp)
Sends a command without data phase.
Definition: hal_wspi.c:222
snorStart
void snorStart(SNORDriver *devp, const SNORConfig *config)
Configures and activates SNOR driver.
Definition: hal_serial_nor.c:660
wspi_command_t::cfg
uint32_t cfg
Transfer configuration field.
Definition: hal_wspi.h:105
wspi_command_t::cmd
uint32_t cmd
Command phase data.
Definition: hal_wspi.h:109
osalDbgAssert
#define osalDbgAssert(c, remark)
Condition assertion.
Definition: osal.h:264
bus_cmd_addr
void bus_cmd_addr(BUSDriver *busp, uint32_t cmd, flash_offset_t offset)
Sends a command followed by a flash address.
Definition: hal_serial_nor.c:475
flash_offset_t
uint32_t flash_offset_t
Type of a flash offset.
Definition: hal_flash.h:113
spiUnselect
void spiUnselect(SPIDriver *spip)
Deasserts the slave select signal.
Definition: hal_spi.c:152
SNORDriver::config
const _base_flash_data SNORConfig * config
Current configuration data.
Definition: hal_serial_nor.h:136
snorStop
void snorStop(SNORDriver *devp)
Deactivates the SNOR driver.
Definition: hal_serial_nor.c:690
snorMemoryUnmap
void snorMemoryUnmap(SNORDriver *devp)
Leaves the memory Mapping mode.
Definition: hal_serial_nor.c:752
bus_cmd_addr_send
void bus_cmd_addr_send(BUSDriver *busp, uint32_t cmd, flash_offset_t offset, size_t n, const uint8_t *p)
Sends a command followed by a flash address and a data transmit phase.
Definition: hal_serial_nor.c:510
bus_cmd
void bus_cmd(BUSDriver *busp, uint32_t cmd)
Sends a naked command.
Definition: hal_serial_nor.c:381
wspiMapFlash
void wspiMapFlash(WSPIDriver *wspip, const wspi_command_t *cmdp, uint8_t **addrp)
Maps in memory space a WSPI flash device.
Definition: hal_wspi.c:331