Neil Armstrong | a9183cd | 2017-05-02 14:55:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Linaro Limited |
| 3 | * Copyright (c) 2017 BayLibre, SAS. |
| 4 | * |
| 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | */ |
| 7 | |
Flavio Ceolin | 67ca176 | 2018-09-14 10:43:44 -0700 | [diff] [blame] | 8 | #ifndef ZEPHYR_DRIVERS_FLASH_FLASH_STM32_H_ |
| 9 | #define ZEPHYR_DRIVERS_FLASH_FLASH_STM32_H_ |
Neil Armstrong | a9183cd | 2017-05-02 14:55:08 +0000 | [diff] [blame] | 10 | |
| 11 | #include <flash_registers.h> |
| 12 | |
Neil Armstrong | 32cb3f0 | 2017-12-04 14:09:59 +0100 | [diff] [blame] | 13 | #if defined(CONFIG_SOC_SERIES_STM32L4X) || \ |
Erwan Gouriou | 82403f6 | 2019-02-14 15:38:52 +0100 | [diff] [blame] | 14 | defined(CONFIG_SOC_SERIES_STM32F0X) || \ |
Francois Ramu | bfc2ea6 | 2019-07-05 15:02:21 +0200 | [diff] [blame] | 15 | defined(CONFIG_SOC_SERIES_STM32F3X) || \ |
| 16 | defined(CONFIG_SOC_SERIES_STM32G0X) |
Anas Nashif | 17ddd17 | 2019-06-25 15:53:47 -0400 | [diff] [blame] | 17 | #include <drivers/clock_control.h> |
Neil Armstrong | a9183cd | 2017-05-02 14:55:08 +0000 | [diff] [blame] | 18 | #include <clock_control/stm32_clock_control.h> |
| 19 | #endif |
| 20 | |
| 21 | struct flash_stm32_priv { |
Neil Armstrong | 32cb3f0 | 2017-12-04 14:09:59 +0100 | [diff] [blame] | 22 | #if defined(CONFIG_SOC_SERIES_STM32F0X) |
| 23 | struct stm32f0x_flash *regs; |
| 24 | /* clock subsystem driving this peripheral */ |
| 25 | struct stm32_pclken pclken; |
Erwan Gouriou | 82403f6 | 2019-02-14 15:38:52 +0100 | [diff] [blame] | 26 | #elif defined(CONFIG_SOC_SERIES_STM32F3X) |
| 27 | struct stm32f3x_flash *regs; |
| 28 | /* clock subsystem driving this peripheral */ |
| 29 | struct stm32_pclken pclken; |
Neil Armstrong | 32cb3f0 | 2017-12-04 14:09:59 +0100 | [diff] [blame] | 30 | #elif defined(CONFIG_SOC_SERIES_STM32F4X) |
Neil Armstrong | a9183cd | 2017-05-02 14:55:08 +0000 | [diff] [blame] | 31 | struct stm32f4x_flash *regs; |
Aurelien Jarno | 6752b5d | 2018-09-02 21:05:52 +0200 | [diff] [blame] | 32 | #elif defined(CONFIG_SOC_SERIES_STM32F7X) |
| 33 | struct stm32f7x_flash *regs; |
Neil Armstrong | a9183cd | 2017-05-02 14:55:08 +0000 | [diff] [blame] | 34 | #elif defined(CONFIG_SOC_SERIES_STM32L4X) |
| 35 | struct stm32l4x_flash *regs; |
| 36 | /* clock subsystem driving this peripheral */ |
| 37 | struct stm32_pclken pclken; |
Erwan Gouriou | d777413 | 2019-03-27 16:52:37 +0100 | [diff] [blame] | 38 | #elif defined(CONFIG_SOC_SERIES_STM32WBX) |
| 39 | struct stm32wbx_flash *regs; |
Francois Ramu | bfc2ea6 | 2019-07-05 15:02:21 +0200 | [diff] [blame] | 40 | #elif defined(CONFIG_SOC_SERIES_STM32G0X) |
| 41 | struct stm32g0x_flash *regs; |
| 42 | /* clock subsystem driving this peripheral */ |
| 43 | struct stm32_pclken pclken; |
Neil Armstrong | a9183cd | 2017-05-02 14:55:08 +0000 | [diff] [blame] | 44 | #endif |
| 45 | struct k_sem sem; |
| 46 | }; |
| 47 | |
Marti Bolivar | 4fea6df | 2017-08-30 14:02:10 -0400 | [diff] [blame] | 48 | #define FLASH_STM32_PRIV(dev) ((struct flash_stm32_priv *)((dev)->driver_data)) |
| 49 | #define FLASH_STM32_REGS(dev) (FLASH_STM32_PRIV(dev)->regs) |
Neil Armstrong | a9183cd | 2017-05-02 14:55:08 +0000 | [diff] [blame] | 50 | |
Marti Bolivar | 32482e9 | 2017-08-30 16:39:26 -0400 | [diff] [blame] | 51 | #ifdef CONFIG_FLASH_PAGE_LAYOUT |
| 52 | static inline bool flash_stm32_range_exists(struct device *dev, |
| 53 | off_t offset, |
| 54 | u32_t len) |
| 55 | { |
| 56 | struct flash_pages_info info; |
| 57 | |
| 58 | return !(flash_get_page_info_by_offs(dev, offset, &info) || |
| 59 | flash_get_page_info_by_offs(dev, offset + len - 1, &info)); |
| 60 | } |
| 61 | #endif /* CONFIG_FLASH_PAGE_LAYOUT */ |
| 62 | |
Marti Bolivar | 4fea6df | 2017-08-30 14:02:10 -0400 | [diff] [blame] | 63 | bool flash_stm32_valid_range(struct device *dev, off_t offset, |
| 64 | u32_t len, bool write); |
Neil Armstrong | a9183cd | 2017-05-02 14:55:08 +0000 | [diff] [blame] | 65 | |
Marti Bolivar | 4fea6df | 2017-08-30 14:02:10 -0400 | [diff] [blame] | 66 | int flash_stm32_write_range(struct device *dev, unsigned int offset, |
| 67 | const void *data, unsigned int len); |
Neil Armstrong | a9183cd | 2017-05-02 14:55:08 +0000 | [diff] [blame] | 68 | |
Marti Bolivar | 4fea6df | 2017-08-30 14:02:10 -0400 | [diff] [blame] | 69 | int flash_stm32_block_erase_loop(struct device *dev, unsigned int offset, |
| 70 | unsigned int len); |
Neil Armstrong | a9183cd | 2017-05-02 14:55:08 +0000 | [diff] [blame] | 71 | |
Marti Bolivar | 4fea6df | 2017-08-30 14:02:10 -0400 | [diff] [blame] | 72 | int flash_stm32_wait_flash_idle(struct device *dev); |
Neil Armstrong | a9183cd | 2017-05-02 14:55:08 +0000 | [diff] [blame] | 73 | |
Erwan Gouriou | d777413 | 2019-03-27 16:52:37 +0100 | [diff] [blame] | 74 | #ifdef CONFIG_SOC_SERIES_STM32WBX |
| 75 | int flash_stm32_check_status(struct device *dev); |
| 76 | #endif /* CONFIG_SOC_SERIES_STM32WBX */ |
| 77 | |
Marti Bolivar | 32482e9 | 2017-08-30 16:39:26 -0400 | [diff] [blame] | 78 | #ifdef CONFIG_FLASH_PAGE_LAYOUT |
| 79 | void flash_stm32_page_layout(struct device *dev, |
| 80 | const struct flash_pages_layout **layout, |
| 81 | size_t *layout_size); |
| 82 | #endif |
Neil Armstrong | a9183cd | 2017-05-02 14:55:08 +0000 | [diff] [blame] | 83 | |
Flavio Ceolin | 67ca176 | 2018-09-14 10:43:44 -0700 | [diff] [blame] | 84 | #endif /* ZEPHYR_DRIVERS_FLASH_FLASH_STM32_H_ */ |